• Welcome, Guest. Please login.
 
October 21, 2019, 03:15:37 am

News:

Welcome to the SQLitening support forums!


SQLite Query Question

Started by Atomic_Sheep, August 05, 2013, 09:16:09 am

Previous topic - Next topic

Atomic_Sheep

Hi Guys,

Trying to write a query whereby I get a row if one of the row's column values equals to a certain value e.g.

SELECT column1, column2 FROM tblTable WHERE column3=7

Doesn't seem to be working, any ideas?

cj

August 05, 2013, 10:05:24 am #1 Last Edit: August 05, 2013, 11:52:50 am by cj
Would have to see the exact insert statement and search.
Probably inserted 7 as '7' or inserted 7 and searched for '7'.

#INCLUDE "\sql\inc\sqlitening.inc"
FUNCTION PBMAIN () AS LONG
  slOpen "test.db3","C"
  slexe "drop table if exists t1"
  slexe "create table if not exists t1(column1,column2,column3)"
  slexe "insert into t1 values(1,2,7)"
  MSGBOX SQL("select column1,column2 from t1 where column3=7")
END FUNCTION
FUNCTION SQL(SqlStatement AS STRING) AS STRING
LOCAL columns,x AS LONG, s AS STRING
slSel SqlStatement: columns = slGetColumnCount
DO WHILE slGetRow
  FOR x = 1 TO Columns
    s = s + slf(x) + ","  'slfx decrypt/uncompress
   NEXT
  ASC(s,LEN(s)) = 13            '$CR after each row
LOOP
FUNCTION = s
END FUNCTION

cj

August 05, 2013, 11:16:51 am #2 Last Edit: August 05, 2013, 11:53:30 am by cj

#DIM ALL
#INCLUDE "\sql\inc\sqlitening.inc"

FUNCTION PBMAIN () AS LONG
  LOCAL squery, sresult,stemp AS STRING
  slOpen "test.db3","C"
  slexe "drop table if exists t1"
  slexe "create table if not exists t1(column1,column2,column3)"
  slexe "insert into t1 values(1,2,7)"
  DO
    stemp = INPUTBOX$("Number in column3","Title","7")
    IF stemp = "" THEN EXIT DO
    stemp = FORMAT$(VAL(stemp)) 'numbers without quotes
    squery = "select column1,column2 from t1 where column3=" & stemp
    query squery,sresult
    ? squery & $CR & sresult,,EXE.FULL$
  LOOP
END FUNCTION
'
SUB query(SqlStatement AS STRING, sresult AS STRING)
LOCAL columns, colnum AS LONG
slSel SqlStatement
columns = slGetColumnCount
RESET sResult
DO WHILE slGetRow
  FOR colnum = 1 TO columns
    sResult = sResult + slf(colnum) + ","
  NEXT
  ASC(sResult,LEN(sResult)) = 13
LOOP
END SUB