Press on the image to return to the main documentation page.
jSQL
The SQL library allows you to create and manage SQL databases. Using this library you can connect to any type of SQL database. See this link for more information.
Gets the number of columns available in the result set.
GetBlob (ColumnNameAsString) AsByte()
Returns the blob stored in the given column. Example: DimBuffer() AsByte Buffer = Cursor.GetBlob("col1")
GetBlob2 (IndexAsInt) AsByte()
Returns the blob stored in the column at the given ordinal. Example: DimBuffer() AsByte Buffer = Cursor.GetBlob2(0)
GetColumnName (IndexAsInt) AsString
Returns the name of the column at the specified index. The first column index is 0.
GetDouble (ColumnNameAsString) AsDouble
Returns the Double value stored in the given column. The value will be converted to Double if it is of different type. Example: Log(Cursor.GetDouble("col2"))
GetDouble2 (IndexAsInt) AsDouble
Returns the Double value stored in the column at the given ordinal. The value will be converted to Double if it is of different type. Example: Log(Cursor.GetDouble2(0))
GetInt (ColumnNameAsString) AsInt
Returns the Int value stored in the given column. The value will be converted to Int if it is of different type. Example: Log(Cursor.GetInt("col2"))
GetInt2 (IndexAsInt) AsInt
Returns the Int value stored in the column at the given ordinal. The value will be converted to Int if it is of different type. Example: Log(Cursor.GetInt2(0))
GetLong (ColumnNameAsString) AsLong
Returns the Long value stored in the given column. The value will be converted to Long if it is of different type. Example: Log(Cursor.GetLong("col2"))
GetLong2 (IndexAsInt) AsLong
Returns the Long value stored in the column at the given ordinal. The value will be converted to Long if it is of different type. Example: Log(Cursor.GetLong2(0))
GetString (ColumnNameAsString) AsString
Returns the String value stored in the given column. The value will be converted to String if it is of different type. Example: Log(Cursor.GetString("col2"))
GetString2 (IndexAsInt) AsString
Returns the String value stored in the column at the given ordinal. The value will be converted to String if it is of different type. Example: Log(Cursor.GetString2(0))
IsInitializedAsBoolean
NextRowAsBoolean
Moves the cursor to the next result. Returns false when the cursor reaches the end. Example: DoWhileResultSet1.Next 'Work with Row Loop
Adds a non-query statement to the batch of statements. The statements are (asynchronously) executed when you call ExecNonQueryBatch. Args parameter can be Null if it is not needed. Example: Fori = 1To1000 sql.AddNonQueryToBatch("INSERT INTO table1 VALUES (?)", Array(Rnd(0, 100000)))
Next DimSenderFilterAsObject = sql.ExecNonQueryBatch("SQL")
WaitFor (SenderFilter) SQL_NonQueryComplete (SuccessAsBoolean)
Log("NonQuery: " & Success)
BeginTransaction
Begins a transaction. A transaction is a set of multiple "writing" statements that are atomically committed, hence all changes will be made or no changes will be made. As a side effect those statements will be executed significantly faster (in the default case a transaction is implicitly created for each statement). It is very important to handle transaction carefully and close them. The transaction is considered successful only if TransactionSuccessful is called. Otherwise no changes will be made. Typical usage: SQL1.BeginTransaction Try 'block of statements like: Fori = 1to1000 SQL1.ExecNonQuery("INSERT INTO table1 VALUES(...)
Next SQL1.TransactionSuccessful Catch Log(LastException.Message)
SQL1.RollBack'no changes will be made EndTry
Close
Closes the database. Does not do anything if the database is not opened or was closed before.
Create a statement object which you can use with ExecCall to call stored procedures.
ExecCall (CallStatementAsObject) AsResultSet
Executes a call statement previously created with CreateCallStatement.
ExecNonQuery (StatementAsString)
Executes a single non query SQL statement. Example: SQL1.ExecNonQuery("CREATE TABLE table1 (col1 TEXT , col2 INTEGER, col3 INTEGER)") It will be significantly faster to explicitly start a transaction before applying any changes to the database.
ExecNonQuery2 (StatementAsString, ArgsAsList)
Executes a single non query SQL statement. The statement can include question marks which will be replaced by the items in the given list. Note that B4J converts arrays to lists implicitly. The values in the list should be strings, numbers or bytes arrays. Example: SQL1.ExecNonQuery2("INSERT INTO table1 VALUES (?, ?, 0)", ArrayAsObject("some text", 2))
ExecNonQueryBatch (EventNameAsString) AsObject
Asynchronously executes a batch of non-query statements (such as INSERT). The NonQueryComplete event is raised after the statements are completed. You should call AddNonQueryToBatch one or more times before calling this method to add statements to the batch. Note that this method internally begins and ends a transaction. Returns an object that can be used as the sender filter for Wait For calls. Example: Fori = 1To1000 sql.AddNonQueryToBatch("INSERT INTO table1 VALUES (?)", Array(Rnd(0, 100000)))
Next DimSenderFilterAsObject = sql.ExecNonQueryBatch("SQL")
WaitFor (SenderFilter) SQL_NonQueryComplete (SuccessAsBoolean)
Log("NonQuery: " & Success)
ExecQuery (QueryAsString) AsResultSet
Executes the query and returns a cursor which is used to go over the results. Example: DimCursorAsResultSet Cursor = SQL1.ExecQuery("SELECT col1, col2 FROM table1")
DoWhileCursor.NextRow Log(Cursor.GetString("col1"))
Log(Cursor.GetInt("col2"))
Loop
Executes the query and returns a cursor which is used to go over the results. The query can include question marks which will be replaced with the values in the array. Example: DimCursorAsResultSet Cursor = sql1.ExecQuery2("SELECT col1 FROM table1 WHERE col3 = ?", ArrayAsString(22)) SQLite will try to convert the string values based on the columns types.
Asynchronously executes the given query. The QueryComplete event will be raised when the results are ready. Returns an object that can be used as the sender filter for Wait For calls. Example: DimSenderFilterAsObject = sql.ExecQueryAsync("SQL", "SELECT * FROM table1", Null)
WaitFor (SenderFilter) SQL_QueryComplete (SuccessAsBoolean, rsAsResultSet)
IfSuccessThen DoWhilers.NextRow Log(rs.GetInt2(0))
Loop rs.Close Else Log(LastException)
EndIf
ExecQuerySingleResult (QueryAsString) AsString
Executes the query and returns the value in the first column and the first row (in the result set). Returns Null if no results were found. Example: DimNumberOfMatchesAsInt NumberOfMatches = SQL1.ExecQuerySingleResult("SELECT count(*) FROM table1 WHERE col2 > 300")
Executes the query and returns the value in the first column and the first row (in the result set). Returns Null if no results were found. Example: DimNumberOfMatchesAsInt NumberOfMatches = SQL1.ExecQuerySingleResult2("SELECT count(*) FROM table1 WHERE col2 > ?", ArrayAsString(300))
Initialize (DriverClassAsString, JdbcUrlAsString)
Initializes the SQL object. You also need to add the JDBC driver jar to your project with the #AdditionalJar attribute. DriverClass - The matching JDBC driver. For example (MySQL): com.mysql.jdbc.Driver JdbcUrl - The connection url. For example (MySQL): jdbc:mysql://localhost/test?characterEncoding=utf8
Asynchronously initializes the SQL connection. The Ready event will be raised when the connection is ready or if an error has occurred. The EventName parameter sets the sub that will handle the Ready event. Example: SubProcess_Globals Dimsql1AsSQL EndSub
SubAppStart (Args() AsString)
sql1.InitializeAsync("sql1", "com.mysql.jdbc.Driver", _
"jdbc:mysql://localhost/example", "username", "password")
StartMessageLoop'only required in a console app EndSub
Opens the SQLite database file. A new database will be created if it does not exist and CreateIfNecessary is true. Note that you should add the following attribute to the main module: #AdditionalJar: sqlite-jdbc-3.7.2 Example: DimSQL1AsSQL SQL1.InitializeSQLite(File.DirApp, "MyDb.db", True)
IsInitializedAsBoolean
Tests whether the database is initialized and opened.
Rollback
Rollbacks the changes from the current transaction and closes the transaction.
TransactionSuccessful
Commits the statements and ends the transaction.
Top