Problem with sqlite database

Fastpho

Member
Licensed User
Longtime User
I have the following dilemma: I have a database with vendors
Vend_codigo following structure, Vend_Descripcion, Vend_Clave
I want the user to place their code and if I show your name then confirm with your password to pass up
You always bring me one seller's description I think the problem is
the cursor1.position = 0 as I do to that position with the entry that the user
From already thank you very much for your time
I show some lines for better understanding

Sub Process_Globals
Dim SQLVEND As SQL
Dim DBFileName As String : DBFileName = "vend.s3db"
Dim DBFileDir As String : DBFileDir = File.DirInternal
'Dim DBFileDir As String : DBFileDir = File.DirRootExternal
Dim DBTableName As String : DBTableName = "vendedor"
Dim ColumnName(3) As String ' names of columns fields
ColumnName(0) = "vend_codigo"
ColumnName(1) = "vend_descripcion"
ColumnName(2) = "vend_clave"

Sub edOperador_EnterPressed
If edOperador.Text.Length =0 Then ' si el dato space obliga a poner dato y retorna el focus
Msgbox("Error debe colocar el numero de operador","")
edOperador.RequestFocus
Return
End If
SQLReadVend
End Sub


Sub SQLReadVend
Dim i As Int
Dim Cursor1 As Cursor
Dim txt As String
Dim entrada As String
Dim e As String
entrada = edOperador.Text
txt = "SELECT * FROM " & DBTableName
Cursor1 = SQLVEND.ExecQuery(txt) ' reads the new database
Cursor1.Position = 0
'Cursor1 = SQLVEND.ExecQuery("SELECT * FROM DBTableName WHERE Vend_Codigo LIKE entrada ")
'Cursor1 = SQLVEND.ExecQuery("SELECT * FROM DBTableName WHERE ID = entrada")
'txt = "SELECT * FROM " & DBTableName & " WHERE " & Vend_Codigo & " = " & entrada
'Cursor1 = SQLVEND.ExecQuery(txt) ' reads the new database

edNombreVend.text=Cursor1.GetString(ColumnName(1))
'e.Text = Cursor1.GetString(vend_descripcion)
'Msgbox(e.text,"3")
'Cursor1.Position = 0
'Log("hola")
'Log(Cursor1.ColumnCount)
End Sub
 

mangojack

Expert
Licensed User
Longtime User
fastpho .. I'm unsure if this even solves your problem .. but was doing nothing anyway.
B4X:
Sub SQLReadVend
Dim i As Int
Dim Cursor1 As Cursor
Dim txt As String
Dim entrada As String
Dim e As String
entrada = edOperador.Text

' get ALL entries from DB
txt = "SELECT * FROM "& DBTableName &" "
Cursor1 = SQLVEND.ExecQuery(txt)
For  i = 0 To Cursor1.RowCount -1
   Cursor1.Position = i
   e = Cursor1.GetString("vend_descripcion")
   Log (e)
Next

'Get a single entry that ' might ' match entrada
txt = "SELECT vend_descripcion  FROM "& DBTableName &" WHERE vend_Codigo = '"& entrada &"' "  ' ....  ' " &  entrada  & " '
Cursor1 = SQLVEND.ExecQuery(txt) 
If Cursor1.RowCount > 0 Then
   Cursor1.Position = 0
   e =  Cursor1.GetString("vend_descripcion")
   Log (e)
Else
   Msgbox("No record was found","Not Found")
End If

'Get a single record you Know will match entrada
txt = "SELECT vend_descripcion FROM "& DBTableName &" WHERE vend_Codigo = '"& entrada &"' "
e =  SQLVEND.ExecQuerySingleResult(txt)
Log (e)

'edNombreVend.text=Cursor1.GetString(ColumnName(1))
'e.Text = Cursor1.GetString(vend_descripcion)
'Msgbox(e.text,"3")
'Cursor1.Position = 0
'Log("hola")
'Log(Cursor1.ColumnCount)

End Sub

I found this thread very useful simplifying SQLite statement syntax
trouble getting grips with sqlite

Cheers mj
 
Upvote 0
Top