Android Question Only one record showing in Table

Douwe Siegersma

Member
Licensed User
Hello,

I'm just starting to use B4A (I come from VB 6.0) and are really very enthousiastic about it.
Because all of my applications make use of a DataBase I started with that.
I use the module Table V2_19 (downloaded it from here) and man! That makes live a lot easier.
On my screen I have two tables. Table1 contains all records (Switches/outlets). In Table2 I want to load only the records of switches with the name selected in table1.

Table2.LoadSQLiteDB(DB_Switches,"Select * FROM Switches WHERE Switches.Name = '" & table1.GetValue(col,row) & "'" ,True)

I Always get only one record i table2. Mostly there are 24 or 48 records (number of ports on a switch) with the same name. I really haven't got a clue.

Plaatje.jpg
 
Last edited:

afields

Member
Licensed User
hello sir. it's very good to use b4x to program android,iphones and also desktop (quite).
About your question i would make you another question:
are you using the right event ( table one) to fire the filling of table2?
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Hello,

I'm just starting to use B4A (I come from VB 6.0) and are really very enthousiastic about it.
Because all of my applications make use of a DataBase I started with that.
I use the module Table V2_19 (downloaded it from here) and man! That makes live a lot easier.
On my screen I have two tables. Table1 contains all records (Switches/outlets). In Table2 I want to load only the records of switches with the name selected in table1.

Table2.LoadSQLiteDB(DB_Switches,"Select * FROM Switches WHERE Switches.Name = '" & table1.GetValue(col,row) & "'" ,True)

I Always get only one record i table2. Mostly there are 24 or 48 records (number of ports on a switch) with the same name. I really haven't got a clue.

Plaatje.jpg
Try changing col, row to 0,row 0 is the Id or select the column by index 2 is Naam if the user clicks another column they will get strange results. Coding it with the specific column index they can click anywhere on the row to populate the second table
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Without having the code it's difficult to give a concrete advice.

In this line:
Table2.LoadSQLiteDB(DB_Switches,"Select * FROM Switches WHERE Switches.Name = '" & table1.GetValue(col,row) & "'" ,True)
Some questions and suggestions:
What is DB_Switches?
Put this line Log(table1.GetValue(col,row), just before the line above to show the value. Is it the correct value?
What are tha values of col and row?
In the Table code, put this line Log(Curs.RowCount) like below. What is the value?
B4X:
Public Sub LoadSQLiteDB(SQLite As SQL, Query As String, AutomaticWidths As Boolean)
   Dim Curs As Cursor
   Curs = SQLite.ExecQuery(Query)
   Log(Curs.RowCount)
Put a breakpoint after each Log line and look in the Logs what happens.

Another possibility is to post your project with the DB file as a zip file, so we can test it in the same conditions as you do.
Generate a zip file in the IDE:

upload_2017-10-24_13-13-41.png
 

Attachments

  • upload_2017-10-24_13-13-19.png
    upload_2017-10-24_13-13-19.png
    13.7 KB · Views: 188
Upvote 0

Douwe Siegersma

Member
Licensed User
Hello all,

DB_Switches is dimensioned as SQL object. Here is the code I use:

Sub Table1_CellClick(col As Int, row As Int)
Select col
Case 2
Table2.LoadSQLiteDB(DB_Switches,"Select * FROM Switches WHERE Switches.Naam = '" & table1.GetValue(col,row) & "'" ,True)
Activity.Title = table1.GetValue(col,row)
End Select
End Sub


Even when I supply the name myself:

Table2.LoadSQLiteDB(DB_Switches,"Select * FROM Switches WHERE Switches.Naam = 'HAR-GEB-A-SER1-SW20'" ,True)

I get only 1 record (the first).
 
Upvote 0

Douwe Siegersma

Member
Licensed User
Hello,

The log returns 1. So there is only one record?
Every item I click in Table1 (column naam) returns the first record of the switches of that name.
I uploaded the project.
 

Attachments

  • MyFirst.zip
    119.1 KB · Views: 151
Upvote 0

Douwe Siegersma

Member
Licensed User
I forgot:
you have to set LeesCSV (boolean) to True. The database will then be created from a CSV file included in DirAssets.
It is the second line in Sub Activity_Create.
 

Attachments

  • outlets.zip
    5.6 KB · Views: 136
Upvote 0

klaus

Expert
Licensed User
Longtime User
I already did it.
I looked at the Portlets.db file created by your program.
In the Switches Table there is only one record with HAR-GEB-A-SER1-SW20!
Therefore, it's normal that you get only one result!

upload_2017-10-24_15-17-41.png


So, what exactly do you expect?
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
I already did it.
I looked at the Portlets.db file created by your program.
In the Switches Table there is only one record with HAR-GEB-A-SER1-SW20!
Therefore, it's normal that you get only one result!

View attachment 60972

So, what exactly do you expect?
Maybe the partial bits at the beginning I guess
 
Upvote 0

Douwe Siegersma

Member
Licensed User
Hello,

I'm getting old(er). :(
Of course there is only one record for a switch in table switches
I should read all records from table Portlets which reference the selected switch.
Thank you all for your assistance. I'm affraid I shall need it more and more in the future.
Best regards,

Douwe
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
A few advices for your project:

1. You don’t need to have two SQL objects pointing onto the same database.
Public DB _Portlets As SQL would be enough.

2. Be careful with the layouts.
You have a ‘standard’ layout variant 320 * 480 scale = 1.
But you have views far outsides the screen. This might work on your device but not on others.

3. Instead of using the LeesCSV variable and change it’s value in the code to generate the database, you could use this code.
B4X:
If FirstTime Then
    If File.Exists(File.DirRootExternal, "Portlets.db") Then
        DB_Portlets.Initialize(File.DirRootExternal, Portlets.db", True)
    Else
        DB_Portlets.Initialize(File.DirRootExternal, Portlets.db", True)
        MaakDB
    End If
End If

4. You should use dip values for view dimensions.
Table1.Left = 25dip instead of Table1.Left = 25
dip = density independant pixels.

5. You should move this kind of code, layout adjustments, to the Designer Scripts in the Designer.
Label1.Left = (Activity.Width - Label1.Width) / 2

6. If in the future you will have more than one Activity, you should move the SQL definition and initialisation to the Starter module.

You might have a look at the B4A Beginner’s Guide and the B4A User’s Guide, links in my signature.
 
Upvote 0

Douwe Siegersma

Member
Licensed User
Hello Klaus,

Thank you for the tips and the support.
I created two SQL objects as a possible solution the ''Problem'
And I'm just using B4A for a week now. Just fooling around a bit.
I will certainly take a look at the guides you recommended.
Thanks again and best regards,

Douwe
 
Upvote 0
Top