I should query some variables in SQLite with part of them,like below code and I need get all numbers in this column that start with 5070 and I use ?*
Number = 5070
point = 5
point_s =25
result1 = cur.execute("""SELECT * FROM C1 WHERE
point = ?
AND point_s = ?
AND trackNumber GLOB '5070*'
AND observed LIKE 'A%'
order by rowid""", (probeType, probe))
with this way get all from column that start with 5070 but when I use ?* for var face with error
result1 = cur.execute("""SELECT * FROM C1 WHERE
point = ?
AND point_s = ?
AND trackNumber GLOB ?*
AND observed LIKE 'A%'
order by rowid""", (probeType, probe, TrackNumber))
but when I use this face an error said "sqlite3.OperationalError: near "AND": syntax error" Is there any way to solve this problem ?
Also I use LIKE instead of GLOB still didn't work and Also I use % and face same error.
CodePudding user response:
Remove the asterisk from the SQL and append it to the argument:
result1 = cur.execute("""SELECT * FROM C1 WHERE
point = ?
AND point_s = ?
AND trackNumber GLOB ?
AND observed LIKE 'A%'
order by rowid""", (probeType, probe, str(TrackNumber) "*"))
If TrackNumber is already a string, the str(...) around it isn't necessary.
