Android Question Flexible Table

Domingo Garcia

Member
Licensed User
Hello, I've been learning the B4A for a couple of weeks and find it a very useful tool. I downloaded the TableV2.22 and used it to display a table in a data form with a SQLite3DB Table of transactions to fill the table in the lower half of the screen. I would like to see an example of double click on a cell and update the cell value and from the new value update the SQLite table. does anybody have an example like that. would I need a separate update button after the data is changed?

Great job with B4A (purchased it 5 days ago)
What is the latest version of the Table Class?
 

klaus

Expert
Licensed User
Longtime User
There is no update method included in the library, you need to do it on your own.
You can use CellClick and CellLongClick events for the celles in the Table like this:
B4X:
Sub Table1_CellClick(col As Int, row As Int)
    Log("row = " & row & "  col = " & col)
End Sub

Sub Table1_CellLongClick(col As Int, row As Int)
    Log("row = " & row & "  col = " & col)
End Sub
You could have a look at the B4A User's Guide (link in my signature), it includes a chapter about SQLite databases with examples.
These examples include an Edit method for whole entries not just for one cell, they don't use the Table class but a WebView, but the principle is the same.
You can find these examples also HERE.
 
Upvote 0

Domingo Garcia

Member
Licensed User
Hello,
I'm trying to fill a table with data from an SQLite database but in my case I have two databases opened. one SQL1 and the other SQL2 but when I call the LoadSQLiteDB2 with command:
Table1.LoadSQLiteDB2(SQL2, stmt, True, Array As String("T", "T", "I", "I", "T"))
I get the error: android.database.sqlite.SQLiteException: no such table: checkout (code 1): , while compiling: SELECT Product, Description, Tipo, Qty, Status FROM checkout WHERE Route = '15A' AND Trndate = '20180126'.
This used to work when I had only one database opened.
 
Upvote 0

Domingo Garcia

Member
Licensed User
SQL2 is initialized in the "Checkout" module that calls the Table class and the table name is correct. This used to work until i separated this table to a second database. Is there an issue with having two databases opened at the same time. I open the first in the Main module and the second is the Checkout module where both are used, in the Activity_Create sub.
If SQL2.IsInitialized = False Then
SQL2.Initialize(File.DirInternal, TRFName, True)
End If
 
Upvote 0

Domingo Garcia

Member
Licensed User
Where is the database file supposed to be placed. I made changes to the tables but it seems to be picking up and old version. I placed the db in the Files folder of the project and I get the message "File 'panwh.db' is not used (warning #15). When i print to log the dbpath it shows: /data/user/0/b4a.example/files...but I can't find that path anywhere. Do I need to run any command to have it pick up the new db file. I haverecompile various times and still get an error.
android.database.sqlite.SQLiteException: no such column: FlgCheck (code 1): , while compiling: SELECT UserID, UserName, UserLevel, PwEncrypt, PwKey, Status, FlgCheck, FlgLoad, FlgMorn, FlgInvt FROM Users Where UserId = ?
there was a spelling error on the column name which I fixed but it's not picking up the change.

#Region Project Attributes
#ApplicationLabel: Checkout
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL1 As SQL
Public DBPath = File.DirInternal As String
Public DBFName As String = "panwh.db"

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Log(DBPath)
If SQL1.IsInitialized = False Then
SQL1.Initialize(DBPath, DBFName, True)
End If
Activity.LoadLayout("login")
CheckWiFi
End Sub

Sub Validate_Login (uid As String, psw As String) As Boolean

Dim Cursor1 As Cursor
Dim stmt As String
Dim pwe As String
Dim rc = False As Boolean
status = ""
stmt = "SELECT UserID, UserName, UserLevel, PwEncrypt, PwKey, Status," _
& " FlgCheck, FlgLoad, FlgMorn, FlgInvt FROM Users Where UserId = ?"
Cursor1 = SQL1.ExecQuery2(stmt, Array As String(uid)) ' Here is where it cancels
Cursor1.Position = 0
status = Cursor1.GetString("Status")
If status = "1" Then
check = Cursor1.GetString("FlgCheck")
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Where is the database file supposed to be placed
You must copy the database file programatically from the Assets folder to the internal folder like this, before you can use it and open it.
B4X:
If File.Exists(File.DirInternal,"panwh.db") =False Then   'you can use your variable name for the file name
        File.Copy(File.DirAssets,"panwh.db",File.DirInternal,"panwh.db")
End If
Please use code tags when you post code. It is easier to decipher it, Domingo.
 
Upvote 0

Domingo Garcia

Member
Licensed User
MR. Mahares, that was it! Now every thing is working. Muchas Gracis. I found LastModified method but it said it doesn't support files in the assets directory.
 
Upvote 0
Top