'Code module
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 7
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private SQL1 As SQL
Private DBName As String = "SQLtest.db"
Private Query As String
Public Dummy As Label
End Sub
Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
Page1.RootPanel.LoadLayout("Page1")
NavControl.ShowPage(Page1)
SQL1.Initialize(File.DirLibrary, DBName, True)
SQL1.BeginTransaction
Try
Query = "CREATE TABLE If Not EXISTS TestTable (ID INTEGER PRIMARY KEY, col1 TEXT, col2 TEXT, col3 TEXT)"
SQL1.ExecNonQuery(Query)
Catch
Log("Error creating table")
Log(LastException.Message)
SQL1.Rollback
End Try
Log("Table created")
SQL1.TransactionSuccessful
Dummy.Text="Finished"
WriteTable
ReadTable
Log("Finished")
End Sub
Sub WriteTable
SQL1.Initialize(File.DirLibrary, DBName, True)
SQL1.BeginTransaction
Try
SQL1.ExecNonQuery("INSERT INTO TestTable (ID,col1,col2,col3) VALUES(1,'This Is col1','this is col2','This is col3')")
SQL1.ExecNonQuery("INSERT INTO TestTable (ID,col1,col2,col3) VALUES(2,'This Is col1','this is col2','This is col3')")
SQL1.ExecNonQuery("INSERT INTO TestTable (ID,col1,col2,col3) VALUES(3,'This Is col1','this is col2','This is col3')")
Catch
SQL1.Rollback
Log("Error inserting table")
Log(LastException.Message)
End Try
Log("Added 3 rows")
SQL1.TransactionSuccessful
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Sub ReadTable
Dim rs As ResultSet
Dim col1,col2,col3 As String
Dim index As Int
SQL1.Initialize(File.DirLibrary, DBName, True)
SQL1.BeginTransaction
Try
rs = SQL1.ExecQuery("Select * from TestTable")
Do While rs.nextrow
Log("At top of loop")
index = rs.GetInt("ID")
Log("Index = " & index)
col1 = rs.GetString("col1")
Log("Col1 = " & col1)
col2 = rs.GetString("col2")
Log("Col2 = " & col2)
col3 = rs.GetString("col3")
Log("Col3 = " & col3)
Loop
Catch
SQL1.Rollback
Log("Error Reading table")
Log(LastException.Message)
End Try
Log("Read 3 rows")
SQL1.TransactionSuccessful
End Sub
Private Sub Application_Background
End Sub