B4J Question [BANano] [SOLVED] Extending Event Driven BANanoSQL with own CallBacks?

Mashiane

Expert
Licensed User
Longtime User
Hi there

This is just a thought...

The current implementation of the event driven BANanoSQL has a callback method for .Execute being

B4X:
Sub SQL_SQLExecuteResult(Tag As String, Result As List)

If perhaps one could have an extra call e.g.
B4X:
.Execute1(qry,args,BANano.CallBack(DoThis))

, this being an extra method that one can specify the callback method to run. Currently with .Execute, one is using a Tag variable to determine the last execute.

The callback could be

B4X:
Sub DoThis(Result As List)
....
.Execute1(qry,arg,BANano.CallBack(DoSomethingElse))
End Sub

Sub DoSomethingElse(Result As List)
....
.Execute1(qry,args,Bye)

ENd Sub

The advantage with this is less complexity as one could loose track with the tagging where a lot of queries are concerned.

Is something like this possible?
 

alwaysbusy

Expert
Licensed User
Longtime User
Something like this may be added in the future:

B4X:
Sub SQL_SQLOpened()
   SQL.ExecuteCallback("CREATE TABLE IF NOT EXISTS flights (flightNo INT, fromCity STRING, toCity STRING, isInTheAir BOOL)", Null, Me, "mycreate")
End Sub

' MUST be this definition.  No params can be added or removed!
Sub MyCreate(success As Boolean, Result As List, Reason As String) 'ignore
   Log("Creation: " & success)
   SQL.Execute("SELECT COUNT(*) AS myCount FROM flights;", Null, "COUNT")
End Sub
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
SQL.ExecuteCallback("CREATE TABLE IF NOT EXISTS flights (flightNo INT, fromCity STRING, toCity STRING, isInTheAir BOOL)", Null, Me, "mycreate")

"fromCity STRING"

I don't see in any SQL dialect where this is valid.. TEXT, Varcar(100, etc..) is.

When copying from one table structure output (MySql, SQLite - for example) - to create a new table - the above would have to be modified to accommodate the import statement .

SQLite: for example... (TEXT for STRING)

B4X:
CREATE TABLE [divmast] (
  [id] INTEGER PRIMARY KEY,
  [name] TEXT,
  [country_id] INTEGER,
  [region_id] INTEGER,
  [city_id] INTEGER,
  [spare1] TEXT,
  [spare2] TEXT,
  [spare3] TEXT);

To use this sample in MySQL, I must remove the ( [] ) from each line to work...
Now, one would have to replace STRING with TEXT to work from your example...

Just a thought and observation...
(can't we all just get along - with the same syntax)...
 
Last edited:
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
"fromCity STRING"

I don't see in any SQL dialect where this is valid.. TEXT, Varcar(100, etc..) is.

You are correct. However, alaSQL (the javascript lib BAnanoSQL wraps) does allow it:
  • Column Types
    • JavaScript data types
      • String
      • Number
      • Boolean
      • Date and ISODate
      • Emun
    • ANSI SQL types
    • SQLite, Oracle, MySQL, SQL Server, Postgres data types mapping
I guess they allow it to bridge both Javascript and SQL better for everyone. Normally, javascript (not using node.js) can't make such SQL queries. Most libraries in JS which allow a direct connection to e.g. a MySQL use a very different syntax (which I personally am not very fond of). I'm more of a fan of normal SQL commands and alaSQL seems to be able to do them.
 
Upvote 0
Top