****-----Code of Starter Module-----****
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public sql1 As SQL
Public dbpath="D:\B4A\Files\data.db" As String
Public dbname="data.db" As String
Public sqlinit As SQL
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
If File.Exists(dbpath,dbname) = True Then
sql1.Initialize(dbpath,dbname,True)
Else
sql1.Initialize(dbpath,dbname,False)
End If
If File.Exists(dbpath,dbname)=True Then
sql1.Initialize(dbpath,dbname,True)
Else
File.Copy(File.DirAssets,dbname,dbpath,dbname)
sql1.Initialize(dbpath,dbname,True)
End If
End Sub
*****-----Code of Main Module-----********
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public sql1 As SQL
Public dbpath As String
Public dbname As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim btnlogin As Button
Dim unametxt As EditText
Dim passtxt As EditText
Public idtxt As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
If FirstTime Then
If File.Exists(File.DirInternal, "data.db") = False Then
sql1.Initialize(File.DirInternal,"data.db",True)
CreateDatabase
End If
End If
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
If sql1.IsInitialized = False Then
sql1.Initialize(File.DirInternal,"data.db",True)
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
sql1.Close
End If
End Sub
Sub unametxt_TextChanged (Old As String, New As String)
End Sub
Sub passtxt_TextChanged (Old As String, New As String)
End Sub
Sub CreateDatabase'(id1 As Int,name1 As String,pass1 As String)
Private query As String
query = "CREATE TABLE data (id Integer Primary Key,Name TEXT,Password TEXT)"
sql1.ExecNonQuery(query)
End Sub
Public Sub AddEntry(id As Int , Name As String,Password As String)
Private query As String
Private cursor1 As Cursor
Private id As Int
query = "SELCET * FROM data where id = ? AND Name = ? AND Password = ?"
cursor1 = sql1.ExecQuery2(query,Array As String(unametxt.Text,passtxt.Text))
If cursor1.RowCount>0 Then
ToastMessageShow("This Entry is Already Exist", False)
Else
query = "INSERT INTO data VALUES (NULL, ?, ?)"
sql1.ExecNonQuery2(query, Array As String(unametxt.text,passtxt.text))
ToastMessageShow("Entery Added", False)
id = sql1.ExecQuerySingleResult("SELECT max(id) from data")
idtxt.Text=id
'RowNumber = RowNumber + 1
End If
cursor1.Close
End Sub