mirror of
https://github.com/KeymonSoft/AdditionalLibs.git
synced 2026-04-17 19:36:30 +00:00
Commit inicial
This commit is contained in:
527
B4A/JdbcSQL.xml
Normal file
527
B4A/JdbcSQL.xml
Normal file
@@ -0,0 +1,527 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<doclet-version-NOT-library-version>1.06</doclet-version-NOT-library-version>
|
||||
<class>
|
||||
<name>anywheresoftware.b4j.objects.SQL</name>
|
||||
<shortname>JdbcSQL</shortname>
|
||||
<owner CheckForReinitialize="true">process</owner>
|
||||
<event>QueryComplete (Success As Boolean, Crsr As JdbcResultSet)</event>
|
||||
<event>NonQueryComplete (Success As Boolean)</event>
|
||||
<event>Ready (Success As Boolean)</event>
|
||||
<permission>android.permission.INTERNET</permission>
|
||||
<method>
|
||||
<name>Initialize</name>
|
||||
<comment>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</comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>DriverClass</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>JdbcUrl</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>BeginTransaction</name>
|
||||
<comment>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:<code>
|
||||
SQL1.BeginTransaction
|
||||
Try
|
||||
'block of statements like:
|
||||
For i = 1 to 1000
|
||||
SQL1.ExecNonQuery("INSERT INTO table1 VALUES(...)
|
||||
Next
|
||||
SQL1.TransactionSuccessful
|
||||
Catch
|
||||
Log(LastException.Message)
|
||||
SQL1.RollBack 'no changes will be made
|
||||
End Try
|
||||
</code></comment>
|
||||
<returntype>void</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecNonQuery2</name>
|
||||
<comment>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:<code>
|
||||
SQL1.ExecNonQuery2("INSERT INTO table1 VALUES (?, ?, 0)", Array As Object("some text", 2))</code></comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>Statement</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecQuerySingleResult</name>
|
||||
<comment>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:<code>
|
||||
Dim NumberOfMatches As Int
|
||||
NumberOfMatches = SQL1.ExecQuerySingleResult("SELECT count(*) FROM table1 WHERE col2 > 300")</code></comment>
|
||||
<returntype>java.lang.String</returntype>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecNonQueryBatch</name>
|
||||
<comment>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:<code>
|
||||
For i = 1 To 1000
|
||||
sql.AddNonQueryToBatch("INSERT INTO table1 VALUES (?)", Array(Rnd(0, 100000)))
|
||||
Next
|
||||
Dim SenderFilter As Object = sql.ExecNonQueryBatch("SQL")
|
||||
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
|
||||
Log("NonQuery: " & Success)</code></comment>
|
||||
<returntype>java.lang.Object</returntype>
|
||||
<parameter>
|
||||
<name>ba</name>
|
||||
<type>anywheresoftware.b4a.BA</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>EventName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>CreateCallStatement</name>
|
||||
<comment>Create a statement object which you can use with ExecCall to call stored procedures.</comment>
|
||||
<returntype>java.lang.Object</returntype>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>InitializeSQLite</name>
|
||||
<comment>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:
|
||||
<code>#AdditionalJar: sqlite-jdbc-3.7.2</code>
|
||||
Example:<code>
|
||||
Dim SQL1 As SQL
|
||||
SQL1.InitializeSQLite(File.DirApp, "MyDb.db", True)</code></comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>Dir</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>FileName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>CreateIfNecessary</name>
|
||||
<type>boolean</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecQueryAsync</name>
|
||||
<comment>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:<code>
|
||||
Dim SenderFilter As Object = sql.ExecQueryAsync("SQL", "SELECT * FROM table1", Null)
|
||||
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As JdbcResultSet)
|
||||
If Success Then
|
||||
Do While rs.NextRow
|
||||
Log(rs.GetInt2(0))
|
||||
Loop
|
||||
rs.Close
|
||||
Else
|
||||
Log(LastException)
|
||||
End If</code></comment>
|
||||
<returntype>java.lang.Object</returntype>
|
||||
<parameter>
|
||||
<name>ba</name>
|
||||
<type>anywheresoftware.b4a.BA</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>EventName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>TransactionSuccessful</name>
|
||||
<comment>Commits the statements and ends the transaction.</comment>
|
||||
<returntype>void</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>AddNonQueryToBatch</name>
|
||||
<comment>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:<code>
|
||||
For i = 1 To 1000
|
||||
sql.AddNonQueryToBatch("INSERT INTO table1 VALUES (?)", Array(Rnd(0, 100000)))
|
||||
Next
|
||||
Dim SenderFilter As Object = sql.ExecNonQueryBatch("SQL")
|
||||
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
|
||||
Log("NonQuery: " & Success)</code></comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>Statement</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>Close</name>
|
||||
<comment>Closes the database.
|
||||
Does not do anything if the database is not opened or was closed before.</comment>
|
||||
<returntype>void</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>InitializeAsync</name>
|
||||
<comment>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:<code>
|
||||
Sub Process_Globals
|
||||
Dim sql1 As SQL
|
||||
End Sub
|
||||
|
||||
Sub AppStart (Args() As String)
|
||||
sql1.InitializeAsync("sql1", "com.mysql.jdbc.Driver", _
|
||||
"jdbc:mysql://localhost/example", "username", "password")
|
||||
StartMessageLoop 'only required in a console app
|
||||
End Sub
|
||||
|
||||
Sub sql1_Ready (Success As Boolean)
|
||||
Log(Success)
|
||||
If Success = False Then
|
||||
Log(LastException)
|
||||
Return
|
||||
End If
|
||||
Dim rs As JdbcResultSet = sql1.ExecQuery("SELECT table_name FROM information_schema.tables")
|
||||
Do While rs.NextRow
|
||||
Log(rs.GetString2(0))
|
||||
Loop
|
||||
rs.Close
|
||||
End Sub</code></comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>ba</name>
|
||||
<type>anywheresoftware.b4a.BA</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>EventName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>DriverClass</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>JdbcUrl</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>UserName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Password</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecQuery</name>
|
||||
<comment>Executes the query and returns a cursor which is used to go over the results.
|
||||
Example:<code>
|
||||
Dim Cursor As JdbcResultSet
|
||||
Cursor = SQL1.ExecQuery("SELECT col1, col2 FROM table1")
|
||||
Do While Cursor.NextRow
|
||||
Log(Cursor.GetString("col1"))
|
||||
Log(Cursor.GetInt("col2"))
|
||||
Loop</code></comment>
|
||||
<returntype>anywheresoftware.b4j.objects.SQL.ResultSetWrapper</returntype>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecQuerySingleResult2</name>
|
||||
<comment>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:<code>
|
||||
Dim NumberOfMatches As Int
|
||||
NumberOfMatches = SQL1.ExecQuerySingleResult2("SELECT count(*) FROM table1 WHERE col2 > ?", Array As String(300))</code></comment>
|
||||
<returntype>java.lang.String</returntype>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecCall</name>
|
||||
<comment>Executes a call statement previously created with CreateCallStatement.</comment>
|
||||
<returntype>anywheresoftware.b4j.objects.SQL.ResultSetWrapper</returntype>
|
||||
<parameter>
|
||||
<name>CallStatement</name>
|
||||
<type>java.lang.Object</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecNonQuery</name>
|
||||
<comment>Executes a single non query SQL statement.
|
||||
Example:<code>
|
||||
SQL1.ExecNonQuery("CREATE TABLE table1 (col1 TEXT , col2 INTEGER, col3 INTEGER)")</code>
|
||||
It will be significantly faster to explicitly start a transaction before applying any changes to the database.</comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>Statement</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>Initialize2</name>
|
||||
<comment>Similar to Initialize method. Passes the given UserName and Password to the database.</comment>
|
||||
<returntype>void</returntype>
|
||||
<parameter>
|
||||
<name>DriverClass</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>JdbcUrl</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>UserName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Password</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>ExecQuery2</name>
|
||||
<comment>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:<code>
|
||||
Dim Cursor As JdbcResultSet
|
||||
Cursor = sql1.ExecQuery2("SELECT col1 FROM table1 WHERE col3 = ?", Array As String(22))</code>
|
||||
SQLite will try to convert the string values based on the columns types.</comment>
|
||||
<returntype>anywheresoftware.b4j.objects.SQL.ResultSetWrapper</returntype>
|
||||
<parameter>
|
||||
<name>Query</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>Args</name>
|
||||
<type>anywheresoftware.b4a.objects.collections.List</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>Rollback</name>
|
||||
<comment>Rollbacks the changes from the current transaction and closes the transaction.</comment>
|
||||
<returntype>void</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>IsInitialized</name>
|
||||
<comment>Tests whether the database is initialized and opened.</comment>
|
||||
<returntype>boolean</returntype>
|
||||
</method>
|
||||
</class>
|
||||
<class>
|
||||
<name>anywheresoftware.b4j.objects.SQL.ResultSetWrapper</name>
|
||||
<shortname>JdbcResultSet</shortname>
|
||||
<objectwrapper>java.sql.ResultSet</objectwrapper>
|
||||
<owner>process</owner>
|
||||
<method>
|
||||
<name>GetInt</name>
|
||||
<comment>Returns the Int value stored in the given column.
|
||||
The value will be converted to Int if it is of different type.
|
||||
Example:<code>
|
||||
Log(Cursor.GetInt("col2"))</code></comment>
|
||||
<returntype>int</returntype>
|
||||
<parameter>
|
||||
<name>ColumnName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetColumnName</name>
|
||||
<comment>Returns the name of the column at the specified index.
|
||||
The first column index is 0.</comment>
|
||||
<returntype>java.lang.String</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetLong</name>
|
||||
<comment>Returns the Long value stored in the given column.
|
||||
The value will be converted to Long if it is of different type.
|
||||
Example:<code>
|
||||
Log(Cursor.GetLong("col2"))</code></comment>
|
||||
<returntype>java.lang.Long</returntype>
|
||||
<parameter>
|
||||
<name>ColumnName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetBlob2</name>
|
||||
<comment>Returns the blob stored in the column at the given ordinal.
|
||||
Example:<code>
|
||||
Dim Buffer() As Byte
|
||||
Buffer = Cursor.GetBlob2(0)</code></comment>
|
||||
<returntype>byte[]</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetLong2</name>
|
||||
<comment>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:<code>
|
||||
Log(Cursor.GetLong2(0))</code></comment>
|
||||
<returntype>java.lang.Long</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetDouble</name>
|
||||
<comment>Returns the Double value stored in the given column.
|
||||
The value will be converted to Double if it is of different type.
|
||||
Example:<code>
|
||||
Log(Cursor.GetDouble("col2"))</code></comment>
|
||||
<returntype>java.lang.Double</returntype>
|
||||
<parameter>
|
||||
<name>ColumnName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetBlob</name>
|
||||
<comment>Returns the blob stored in the given column.
|
||||
Example:<code>
|
||||
Dim Buffer() As Byte
|
||||
Buffer = Cursor.GetBlob("col1")</code></comment>
|
||||
<returntype>byte[]</returntype>
|
||||
<parameter>
|
||||
<name>ColumnName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>Close</name>
|
||||
<comment>Closes the cursor and frees resources.</comment>
|
||||
<returntype>void</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetInt2</name>
|
||||
<comment>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:<code>
|
||||
Log(Cursor.GetInt2(0))</code></comment>
|
||||
<returntype>int</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetString</name>
|
||||
<comment>Returns the String value stored in the given column.
|
||||
The value will be converted to String if it is of different type.
|
||||
Example:<code>
|
||||
Log(Cursor.GetString("col2"))</code></comment>
|
||||
<returntype>java.lang.String</returntype>
|
||||
<parameter>
|
||||
<name>ColumnName</name>
|
||||
<type>java.lang.String</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetString2</name>
|
||||
<comment>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:<code>
|
||||
Log(Cursor.GetString2(0))</code></comment>
|
||||
<returntype>java.lang.String</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>GetDouble2</name>
|
||||
<comment>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:<code>
|
||||
Log(Cursor.GetDouble2(0))</code></comment>
|
||||
<returntype>java.lang.Double</returntype>
|
||||
<parameter>
|
||||
<name>Index</name>
|
||||
<type>int</type>
|
||||
</parameter>
|
||||
</method>
|
||||
<method>
|
||||
<name>NextRow</name>
|
||||
<comment>Moves the cursor to the next result. Returns false when the cursor reaches the end.
|
||||
Example:<code>
|
||||
Do While ResultSet1.Next
|
||||
'Work with Row
|
||||
Loop</code></comment>
|
||||
<returntype>boolean</returntype>
|
||||
</method>
|
||||
<method>
|
||||
<name>IsInitialized</name>
|
||||
<comment></comment>
|
||||
<returntype>boolean</returntype>
|
||||
</method>
|
||||
<property>
|
||||
<name>ColumnCount</name>
|
||||
<returntype>int</returntype>
|
||||
<comment>Gets the number of columns available in the result set.</comment>
|
||||
</property>
|
||||
</class>
|
||||
<version>1.5</version>
|
||||
<comment>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>link|http://www.basic4ppc.com/android/forum/threads/sql-tutorial.35185/</link> for more information.</comment>
|
||||
</root>
|
||||
Reference in New Issue
Block a user