B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private SQL1 As SQL
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
SQL1.Initialize(File.DirInternal, "MyDb.db", True)
Button1_Click
End Sub
Private Sub Button1_Click
SQL1.ExecNonQuery("DROP TABLE IF EXISTS client")
Log("create table")
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS client (id INTEGER PRIMARY KEY AUTOINCREMENT)")
Log("select before creating columns")
Dim rs As ResultSet = SQL1.ExecQuery("SELECT * FROM client LIMIT 1")
Do While rs.NextRow
LogColor(rs.ColumnCount, xui.Color_Green)
Loop
Log("create column in table")
SQL1.ExecNonQuery("ALTER TABLE client ADD COLUMN name TEXT DEFAULT ''")
SQL1.ExecNonQuery("ALTER TABLE client ADD COLUMN age TEXT DEFAULT ''")
SQL1.ExecNonQuery("ALTER TABLE client ADD COLUMN country TEXT DEFAULT ''")
Log("insert")
SQL1.ExecNonQuery2("INSERT INTO client VALUES (null, ?, ?, ?)", Array As Object("joe", 22, "brazil"))
Log("1 - select after creating the columns")
Dim rs As ResultSet = SQL1.ExecQuery("SELECT * FROM client LIMIT 1")
Do While rs.NextRow
LogColor("rs.ColumnCount: " & rs.ColumnCount, xui.Color_Green)
Loop
Log("2 - select after creating the columns")
Dim rs As ResultSet = SQL1.ExecQuery("SELECT * FROM client LIMIT 1")
Do While rs.NextRow
LogColor("rs.ColumnCount: " & rs.ColumnCount, xui.Color_Green)
Loop
End Sub
B4X:
Logger connected to: motorola moto e(7) power
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
create table
select before creating columns
create column in table
insert
1 - select after creating the columns
rs.ColumnCount: 1
2 - select after creating the columns
rs.ColumnCount: 4
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
I'm creating a table with just one field.
After that I do a select to check how many records are in the table and display the number of columns, (as I didn't insert any records in the table, nothing comes up).
then I include 3 new fields in the table.
After the table has 4 fields, I do an insert, everything goes well, without any errors so far.
After the insert, I do a select to bring me all the records in the table, but due to some error it only brings me the id field (which was the field created along with the table).
The strange thing is that I execute the same select twice, the first time only brings me the id field. the second time brings me the 4 fields (id, name, age, parents).