sqlite error

croccio

Member
i've a sqlite database.
when i've do a select i got an error.

this is the code

B4X:
Sub cmdTutte_Click
   Dim frasi As String
   Dim n As Float
    lstfrasi.Clear 
   
    n=SQL1.ExecQuerySingleResult("SELECT count(*) FROM TB_TEMI")
   
    Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery("SELECT TITOLO, TRACCIA FROM TB_TEMI where titolo!='z' order by TITOLO")
    For i = 0 To Cursor.RowCount - 5
        Cursor.Position = i
        lstfrasi.AddTwoLines (Cursor.getstring("TITOLO"), Cursor.getstring("TRACCIA"))
    Next
    Cursor.Close

End Sub

this is the structure of database

h_ttp://imageshack.us/photo/my-images/860/62387738.png

and this the error

h_ttp://imageshack.us/photo/my-images/210/38246890.png

read at the bottom of image for error

how can i solve it??
 

karld

Active Member
Licensed User
Longtime User
What is your variable Z defined as?
What is lstfrasi defined as?

SQLite is trying to convert type between BLOB and String.

Somewhere you have a variable defined as BLOB and you are now referencing it as type string.

I can't narrow it down any further without seeing the rest of your code.

Karl
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Try this:

B4X:
Sub cmdTutte_Click

   Dim frasi As String
   Dim n As Float
   Dim dbTITOLO, dbTRACCIA As String  '<--Add this

   lstfrasi.Clear 
   
    n=SQL1.ExecQuerySingleResult("SELECT count(*) FROM TB_TEMI")
   
    Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery("SELECT TITOLO, TRACCIA FROM TB_TEMI where titolo != 'z' order by TITOLO")
    For i = 0 To Cursor.RowCount - 5
        Cursor.Position = i

        'And these 2 lines
        dbTITOLO = Cursor.getstring("TITOLO")
        dbTRACCIA = Cursor.getstring("TRACCIA")

        lstfrasi.AddTwoLines(dbTITOLO, dbTRACCIA)
    Next
    Cursor.Close

End Sub
 
Upvote 0

croccio

Member
here u are the project. the code of njdude wan't work. can u help me to resolve my problem?

h_ttp://dl.dropbox.com/u/7688709/temi%20svolti.zip
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok, you have some issues:

1- There's no 'Casual.png' included in your project. (I have commented that line - Line 58)
2- Your DB was sort of corrupted that's why you were getting those BLOB errors, it was due to the CORPO column having a HUGE text (I've fixed that), maybe your SQLite editor got confused or something.
3- There's no 'modididire" table (Line 266) you will have to correct that.

HERE is the corrected file.
 
Last edited:
Upvote 0

karld

Active Member
Licensed User
Longtime User
NJDude seems to be on the right track. I'll go back to snooping mode now..
 
Upvote 0

croccio

Member

i know the other problem and i would fix them after i fix the problem of 'blob'

thanku i try it now
 
Upvote 0

croccio

Member
it work
how do u restore my db file?

an other question. how can i do a query using a variable of my software?

for example i woul take 'n' element from my db where n is a casual number
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
it work
how do u restore my db file?

an other question. how can i do a query using a variable of my software?

for example i woul take 'n' element from my db where n is a casual number

I fixed your DB by refreshing the CORPO column.

I don't understand what you mean by "for example i woul take 'n' element from my db where n is a casual number"; what are you trying to achive?
 
Upvote 0

croccio

Member
B4X:
dim n as int
n=rnd(20)
Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery("SELECT id, titolo, traccia, corpo FROM tb_temi WHERE id=[COLOR="Red"]n[/COLOR]")
For i = 0 To Cursor.RowCount - 1
        Cursor.Position = i
   Msgbox ("Traccia: " & traccia & CRLF & CRLF & corpo, titolo)
Next
Cursor.Close

n is the variable of program. how can i do it?

noe i'm doing so, but is there anywau to do it in the query??
dim n as int
B4X:
n=rnd(20)
Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery("SELECT id, titolo, traccia, corpo FROM tb_temi WHERE id=[COLOR="Red"]n[/COLOR]")
For i = 0 To Cursor.RowCount - 1
        Cursor.Position = i
        if id=n then
           Msgbox ("Traccia: " & traccia & CRLF & CRLF & corpo, titolo)
        end if
Next
Cursor.Close
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You'd need ExecQuery2 and something like this:

B4X:
dim n as int
Dim Option As String
n=rnd(20)
Option = "<font color="&Quote&"Red"&Quote&">"&n&"</font>"
Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery2("SELECT id, titolo, traccia, corpo FROM tb_temi WHERE id= ?",Array As String(Option))
For i = 0 To Cursor.RowCount - 1
        Cursor.Position = i
    Msgbox ("Traccia: " & traccia & CRLF & CRLF & corpo, titolo)
Next
Cursor.Close
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I haven't tested it but it should work, I'm not at my developing PC right now.

B4X:
Cursor = SQL1.ExecQuery("SELECT id, titolo, traccia, corpo FROM tb_temi WHERE id='" & n & "'")

If Cursor.RowCount = 0 then

   MsgBox("Nothing Found", "")

Else

   Traccia = Cursor.GetString("traccia")
   Corpo = Cursor.GetString("corpo")
   Titolo = Cursor.GetString("titolo")
 
   Msgbox ("Traccia: " & traccia & CRLF & CRLF & corpo, titolo)

End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…