Android Question DBUtils

Status
Not open for further replies.

powerino

Active Member
Licensed User
Hi, ma app works with BlueStacks, but with a real device i have a problem with this code:
B4X:
'Executes the query and returns the result as a list of arrays.
'Each item in the list is a strings array.
'StringArgs - Values to replace question marks in the query. Pass Null if not needed.
'Limit - Limits the results. Pass 0 for all results.
Public Sub ExecuteMemoryTable(SQL As SQL, Query As String, StringArgs() As String, Limit As Int) As List
    Dim cur As ResultSet
    If StringArgs = Null Then
        Dim StringArgs(0) As String
    End If
    cur = SQL.ExecQuery2(Query, StringArgs)
    Log("ExecuteMemoryTable: " & Query)
    Dim table As List
    table.Initialize
    Do While cur.NextRow
        Dim values(cur.ColumnCount) As String
        For col = 0 To cur.ColumnCount - 1
            values(col) = cur.GetString2(col)
        Next
        table.Add(values)
        If Limit > 0 And table.Size >= Limit Then Exit
    Loop
    cur.Close
    Return table
End Sub

it seems that the query does not return results, so it is empty and does not fill the "list" ... is it possible that I have to install sqlite on the device?
 

powerino

Active Member
Licensed User
[QUOTE = "themr23, post: 705915, membro: 47393"]
Hai provato a cercare nel registro non filtrato?
[/CITAZIONE]
i do not understand what you meen, sorry
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Why do you think that the problem is with the code sample you show? There could be many other reasons. Are you sure that the data is in the database? Are you sure that the query is doing what you think it is doing? If you had to ask if you needed to install sqlite then there are obviously many things that you do not know. Maybe try a simpler query, or use another app to see what is actually in your database file.
 
Upvote 0

powerino

Active Member
Licensed User
[QUOTE = "Brian Dean, post: 705924, membro: 69362"]
Perché pensi che il problema sia con l'esempio di codice che mostri? Potrebbero esserci molte altre ragioni. Sei sicuro che i dati siano nel database? Sei sicuro che la query stia facendo ciò che pensi stia facendo? Se hai dovuto chiedere se era necessario installare sqlite, ovviamente ci sono molte cose che non conosci. Forse prova una query più semplice o usa un'altra app per vedere cosa c'è effettivamente nel tuo file di database.
[/CITAZIONE]

con bluestaks funziona, con vero dispositivo no!
The problen is with query results, THE SAME QUERY!
 
Upvote 0

powerino

Active Member
Licensed User
ho provato a creare un nuovo sub, che fa lo stesso lavoro, e ho lo stesso problema con la query, perché non restituisce il record
Alla linea 11 Connection.myCUR3.RowCount - 1

B4X:
Sub RiempiFile
    
    Dim id As String
    Dim descr As String
    Dim tot As String
    
    'creo in nome del file
    PreparaNomeFile
    
    Connection.myCUR3 = Connection.mySQL.ExecQuery("SELECT * FROM LavoroTB")
    For i = 0 To Connection.myCUR3.RowCount - 1
        Connection.myCUR3.Position = i
    
        id=Connection.myCUR3.GetString("ID")
        descr=Connection.myCUR3.GetString("Descrizione")
        tot=Connection.myCUR3.GetString("Tot")
        
    
        list(i) = id & "|" & descr & "|" &  tot
    
        'scrivo i dati nel File
        File.WriteList(FullPath, FileName, list)
        
    Next
    
    
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Try something like this. I do not understand spanish or italian or whatever language you are using. This gives you an idea
B4X:
Sub RiempiFile   
    Dim id As String
    Dim descr As String
    Dim tot As String
    Dim myCUR3 As Cursor
    Dim list As List
    list.Initialize
    'creo in nome del file
    PreparaNomeFile    
    myCUR3 = mySQL.ExecQuery("SELECT * FROM LavoroTB")
    Log(myCUR3.RowCount)  'check number of records here
    For i = 0 To myCUR3.RowCount - 1
        myCUR3.Position = i  
        id=myCUR3.GetString("ID")
        descr=myCUR3.GetString("Descrizione")
        tot=myCUR3.GetString("Tot")         
        list.Add(id & "|" & descr & "|" &  tot)
    Next
    myCUR3.Close
    File.WriteList(FullPath, FileName, list)   
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Esiste anche il forum italiano; avevo qualche sospetto, visto il tuo nick ?.

Even an (the) italian forum exists; I suspected that you was italian, given your nick. Users should set their country, in their profile :(

If you are sure that all it's ok on an emulator... most likely you are using two different DBs
 
Upvote 0

powerino

Active Member
Licensed User
[QUOTE = "LucaMs, post: 705933, membro: 51832"]
Esiste anche il forum italiano; avevo qualche sospetto, visto il tuo nick ?.

Esiste persino un (il) forum italiano; Sospettavo che fossi italiano, dato il tuo nick. Gli utenti dovrebbero impostare il proprio paese, nel proprio profilo:(

Se sei sicuro che tutto sia ok su un emulatore ... molto probabilmente stai usando due DB diversi
[/CITAZIONE]
Ho solo collegato il telefono per testare e non so come sia possibile che ci siano 2 DB diversi
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ho solo collegato il telefono per testare e non so come sia possibile che ci siano 2 DB diversi
Qui devi scrivere in inglese; eventualmente scrivi nel forum italiano.
Here you must write in english.

2 DB diversi, intendo dire che magari sull'emulatore stai usando una certa versione del tuo DB e sul dispositivo fisico un'altra.
I mean that maybe you're working on a version of your DB on the emulator and on a different one on your device.
 
Last edited:
Upvote 0

powerino

Active Member
Licensed User
I finally found the problem:
On bluestacks I had filled the table with data, but by connecting the phone the table was empty (I thought the database was the same) and therefore it is clear that the query gave an error. How do I "move" the database from bluestacks to the device? Thank you
 
Upvote 0
Status
Not open for further replies.
Top