Android Example SQLiteLight four simple SQLite projects

klaus

Expert
Licensed User
Longtime User
Try this code instead of ReadDataBaseIDs , not tested:
B4X:
Dim Cursor1 As Cursor
Query ="SELECT " & ColNames(0) & " FROM " & SQLTabelName & " WHERE " & ColNames(1) & " LIKE " & "'%"  & SeaVal & "%'"  & " OR  " & ColNames(2) & " LIKE " & "'%"  & SeaVal & "%'"  & " OR  " & ColNames(3) & " LIKE " & "'%"  & SeaVal & "%'"  & " OR  " & ColNames(4) & " LIKE " & "'%"  & SeaVal & "%'"  '"

Cursor1 = SQL1.ExecQuery(Query)
If Cursor1.RowCount > 0 Then  
    RowNumber = Cursor1.RowCount  
    IDList.Initialize  
    For Row = 0 To  RowNumber - 1
        Cursor1.Position = Row   
        IDList.Add(Cursor1.GetInt(ColNames(0)))  
    Next
    CurrentIndex = 0  
Else
    CurrentIndex = -1     
    ToastMessageShow("No items found", False)
End If
Cursor1.Close
 

3394509365

Active Member
Licensed User
Longtime User
Where can I find this file physically on the phone? (File.DirInternal, "persons.db")
 

3394509365

Active Member
Licensed User
Longtime User
ok

but if I want to use the external sd memory?

I would change the name of the db instead of persons.db?
 
Last edited:

klaus

Expert
Licensed User
Longtime User
You can write on an external sdcard, but you need to know the path for it.
Unfortunately Android doesn't provide a standard path naming for external sdcard.
This means that the path name is different on different devices.
You might have a look HERE.

Since Android 4.4 it is no more possible to write anywhere onto an external sdcard, only into an application special folder, look HERE.
 

3394509365

Active Member
Licensed User
Longtime User
hello everyone I scaricatoo the project (SQLiteLight3 project) and I'm studying, I would like to add a button but I can not figure out where they are created.
 

klaus

Expert
Licensed User
Longtime User
Sorry, I don't understand what exactly what you are speaking of.
In the program the Buttons are all added in the Designer in layout files, no button is added in the code !?
So you can either:
- add buttons in the Designer to any of the layout files.
- add buttons in the code.

Or are you speaking of the Label, EditText and Spinner views in the Edit or Filter activity ?
These are added automatically in the code according to the number columns in the InitEditPanel and InitSpinners routines.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Klaus for this and all of your other contributions to the forum. If I am allowed t quote Beja, "When knowledge and experience is coupled with generosity and selflessness, then we have Klaus."

Two minor issues related to column names with a space:

Column Name: [Last Name]
In SQLite3, set

ColNames(ColNumber) = "[Last Name]"

However,

in sub: UpdateSelectedItem

Curs.GetString expects "Last Name" not "[Last Name]"

I developed a work around, but I wanted to get your view on this.

Best regards.

Sandy
 

klaus

Expert
Licensed User
Longtime User
In SQLiteLight3 you have two arrays one ColNames() with the column names and one ColAliasNames() with names for the columns shown in the table header.
For Last Name, ColNames(2) = "LastName" and ColAliasNames(2) = "Last name".
LastName is used in the database and in the SQL query and 'Last name' is shown in the table header.
The advantage doing this is that you could change the names in the table header without changing the names in the database (different language for example).
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Klaus.

I failed to ask the question correctly. I have an existing table where column names contain spaces. For example,

Existing Column Names
[Date Last Seen on Forum]
[Ask Klaus]
[Person Responsible]

Two minor issues related to column names with a space:
Column Name:[Ask Klaus]

In SQLite3, set
ColNames(ColNumber) = "[Ask Klaus]"

However,
In SQLite3 sub: UpdateSelectedItem
Curs.GetString expects "Ask Klaus" not "[Ask Klaus]"

I developed a work around, but I wanted to get your view on this.

Best regards.
Sandy
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Klaus.

I agree with you - it is better for ColNames not to have spaces. However, the table I am working with contains them.

I found a workaround by creating a second set of column names to accommodate the Curs.GetString expects "Ask Klaus" not "[Ask Klaus]"

Final point on SQLite3 - this is a great tool, Klaus, and like many others, I am grateful you developed it.

Would you consider adding your Flexible Table Class to display the table?

Best regards.

Sandy
 

LucaMs

Expert
Licensed User
Longtime User
I have an existing table where column names contain spaces.

Many DBMS allow the use of column names (and also table names) containing spaces.

For the construction of the query sql, common practice is to use a function that adds the square brackets if they do not already exist.

B4X:
Dim Query As String = "SELECT " & AddSqBr(FieldName) ..."

Sub AddSqBr(Text As String) As String
    If Not(Text.StartsWith("[")) Then
        Text = "[" & Text & "]"
    End If
    Return Text
End Sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…