Comments (11)
From rogerbinns on July 17, 2008 13:24:31
Since you are supplying a Python string, it has to be converted to Unicode since that
is the only type of string that SQLite accepts. (This is before any column affinity
rules are applied by SQLite).
To supply binary data use the buffer class - in your example:
buffer("\xcf\xde")
I will update the documentation section Types to be a little clearer as well as add
something to the example.
Status: Accepted
Labels: Component-Docs
from apsw.
From [email protected] on July 18, 2008 03:32:57
I'm afraid this doesn't work for me:
c.execute("insert into blobs values(?)", buffer("\xFE"))
Traceback (most recent call last):
File "", line 1, in
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 0: ordinal not
in range(128)
from apsw.
From rogerbinns on July 18, 2008 03:38:05
That is because you are not providing a tuple of items like in your first post :-)
It should be:
c.execute("insert into blobs values(?)", (buffer("\xFE"), ) )
from apsw.
From [email protected] on July 18, 2008 10:39:19
True, now it works indeed. Thanks a lot!
from apsw.
From [email protected] on July 18, 2008 10:49:21
This might be a stupid question, but how can I get back a (byte) string from the
buffer that I get when I query the table?
I couldn't find any documentation of the buffer objects on python.org/doc...
from apsw.
From rogerbinns on July 18, 2008 13:15:44
In Python 2 you can turn a buffer into a string by using str or [:]. For example:
x=buffer("abc")
print type( str(x) )
print type( x[:] )
If you look in the index in the Python documentation you'll find some measly doc.
from apsw.
From [email protected] on July 19, 2008 01:34:22
Your example works nicely, but for some reason it does not work if I apply it to the
buffer object returned by the cursor:
c.execute("insert into blobs values(?)", (buffer("\xCF"),))
<apsw.Cursor object at 0xb7db6d10>
res = c.execute("select * from blobs")
a = res.next()
a
(<read-write buffer ptr 0xb7db8d10, size 1 at 0xb7db8cf0>,)
str(a)
'(<read-write buffer ptr 0xb7db8d10, size 1 at 0xb7db8cf0>,)'
I'm using Python 2.5.2
from apsw.
From rogerbinns on July 19, 2008 01:37:43
The cursor iterator returns an entire row as a tuple. You called str on that so that
is exactly what you have printed out - a tuple containing one buffer item.
from apsw.
From [email protected] on July 19, 2008 01:55:19
Brrr... You're of course right again. I probably shouldn't try to learn Python and
apsw at the same time. Thanks a lot for your help and patience!
from apsw.
From rogerbinns on July 19, 2008 02:47:17
There is no problem learning Python and APSW at the same time. Python itself is very
simple although it takes a while to learn "best practise". The paper version of the
Python Cookbook is a good tour of various best practises.
Your "mistake" is assuming that whenever you encounter issues they are bugs. The
chances of you finding bugs in Python, APSW, SQLite etc after just starting using
them is extremely low compared to the underlying issue being in your code or
understand of how things work :-)
from apsw.
From rogerbinns on July 26, 2008 02:47:44
Doc updated in r190
Status: Verified
from apsw.
Related Issues (20)
- Unknown apsw attribute 'SQLiteValues' HOT 3
- Cursor.executemany should be annotated as accepting Iterable[Bindings] instead of Sequence[Bindings] HOT 1
- Implement Unicode TR-29 and TR-14 HOT 1
- error: static declaration of ‘PyLong_AsInt’ in Python 3.13+ HOT 3
- Switch to cosign for signing
- Incorrect values in `colUsed` HOT 2
- Update to Unicode 16.0 when released September 2024 HOT 1
- connection.set_row_trace - excepts; Connection.setrowtrace works HOT 4
- `connection.setrowtrace` stops working when adapters are registered HOT 5
- Datetimes into sqlite via APSW HOT 1
- Revise logging levels
- query execution row and time limits HOT 1
- Support subtypes in functions
- Don't cache pragmas
- con.pragma can't accept blobs HOT 1
- Update Connection.pragma with schema parameter
- Implement SQLITE_FCNTL_VFSNAME
- VFS xRandomness errors need to be unraisable HOT 1
- apsw.ext.query_info should find bound parameters
- Comprehensive dump module
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apsw.