Skip to content Skip to sidebar Skip to footer

Sqlite Data Storage

I am running a sqlite command SELECT address FROM Locations WHERE address='hola' On a data base table The output is only one row even though the result should be 3 rows This

Solution 1:

This is a charset problem. st it is ISO charset st1 and st2 it is UTF-8 charset.

And your query is in ISO charset format.

Solution 2:

After using your sample python code to populate a table in a database, I ran this query:

sqlite> select *, typeof(address) from locations;
id          addresstypeof(address)
----------  ----------  ---------------
1           hola        text           
2           hola        blob           
3           hola        blob           

Two of the values you're inserting are stored as blobs, one as a text string.

From the documentation on how values of different types are compared:

A TEXT value is less than a BLOB value.

That is to say, a string like 'hola' will never be equal to a blob, even if the underlying bytes of the string are identical to the bytes in the blob. That's why only one value is being returned by your SELECT.

Solution 3:

you are confusing comments

""" I'm multi-line comment"""

with strings

"I'm a string"

I suggest you to modify your code as follows

st = "hola"
st1 = st.encode()
st2 =memoryview(st1)

conn = sqlite3.connect('test.sqlite')
cur = conn.cursor()

cur.execute('INSERT INTO Locations(address)VALUES(?)',(st,))
cur.execute('INSERT INTO Locations(address)VALUES(?)',(st1,))
cur.execute('INSERT INTO Locations(address)VALUES(?)',(st2,))

conn.commit()

Post a Comment for "Sqlite Data Storage"