iOS Question Is there a simple B4i isql example?

dnaci

Member
Licensed User
Longtime User
Thank you, Klaus. I do not want to use Webview. I want to use Labels. I added the picture I wanted to do.
isql-b4i.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but you didn't answer my question!
What exactly don't you understand?
In your example above, you have a ReadButton.
OK, but what would you like to see when you click on the button and how.
Or, in other words, when you record an entry with the RecordButton how is it memorized, OK in a database, but how do you expect getting it back.
I think that somewhere you want to see what you have in the database, and then WebView is one solution out of many others.
But you need to be more precise on what you want, need or expect.
If you want to memorize only a few phone numbers a database is for sure not the appropiate method, there are more simple ones.
The simplest is just a text file.
Are you sure that you want only the numbers without any other information who the number belongs to?
You need to think about all this before you begin any coding and when you are clear in your mind begin to think how you could achieve it and then begin coding.
 
Upvote 0

DickD

Active Member
Licensed User
Is there a b4i isql example I can store and view cell phone numbers? I want to save the number I wrote in the Text box with a button. I want to see the number I recorded on a Label. Thank you.

I have reviewed this link. The code works. The code is compiled. But I could not understand.

https://www.b4x.com/android/forum/threads/module-dbutils.46563/#content
Here is the SIMPLE SQL code I wrote as a first experiment to see how SQL works in B4I. I hope it helps. I haven't solved everything about SQL yet like getting pictures in and out of BLOBs (ok with B4A but not with B4I).

B4X:
'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
 
Upvote 0

dnaci

Member
Licensed User
Longtime User
Klaus, I want to learn isql. I have no knowledge of isql. I start to learn with a simple example. When I press the Write button, I want to register the decimal numbers in the text box to the database. When I press the Read button, I want to see the registered numbers in the database on the label.
Thank you DickD. I will examine your code.
 
Upvote 0
Top