Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e7032b0d
Commit
e7032b0d
authored
Aug 10, 2007
by
Gerhard Häring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the sqlite tests pass.
parent
b5032769
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
31 deletions
+28
-31
Lib/sqlite3/test/factory.py
Lib/sqlite3/test/factory.py
+9
-9
Lib/sqlite3/test/types.py
Lib/sqlite3/test/types.py
+3
-3
Lib/sqlite3/test/userfunctions.py
Lib/sqlite3/test/userfunctions.py
+2
-2
Modules/_sqlite/connection.c
Modules/_sqlite/connection.c
+2
-4
Modules/_sqlite/cursor.c
Modules/_sqlite/cursor.c
+8
-10
Modules/_sqlite/row.c
Modules/_sqlite/row.c
+2
-2
Modules/_sqlite/statement.c
Modules/_sqlite/statement.c
+2
-1
No files found.
Lib/sqlite3/test/factory.py
View file @
e7032b0d
...
...
@@ -139,32 +139,32 @@ class TextFactoryTests(unittest.TestCase):
self
.
con
=
sqlite
.
connect
(
":memory:"
)
def
CheckUnicode
(
self
):
austria
=
str
(
"sterreich"
,
"latin1"
)
austria
=
"sterreich"
row
=
self
.
con
.
execute
(
"select ?"
,
(
austria
,)).
fetchone
()
self
.
failUnless
(
type
(
row
[
0
])
==
str
,
"type of row[0] must be unicode"
)
def
CheckString
(
self
):
self
.
con
.
text_factory
=
str
austria
=
str
(
"sterreich"
,
"latin1"
)
self
.
con
.
text_factory
=
bytes
austria
=
"sterreich"
row
=
self
.
con
.
execute
(
"select ?"
,
(
austria
,)).
fetchone
()
self
.
failUnless
(
type
(
row
[
0
])
==
str
,
"type of row[0] must be str
"
)
self
.
failUnless
(
type
(
row
[
0
])
==
bytes
,
"type of row[0] must be bytes
"
)
self
.
failUnless
(
row
[
0
]
==
austria
.
encode
(
"utf-8"
),
"column must equal original data in UTF-8"
)
def
CheckCustom
(
self
):
self
.
con
.
text_factory
=
lambda
x
:
str
(
x
,
"utf-8"
,
"ignore"
)
austria
=
str
(
"sterreich"
,
"latin1"
)
row
=
self
.
con
.
execute
(
"select ?"
,
(
austria
.
encode
(
"latin1"
)
,)).
fetchone
()
austria
=
"sterreich"
row
=
self
.
con
.
execute
(
"select ?"
,
(
austria
,)).
fetchone
()
self
.
failUnless
(
type
(
row
[
0
])
==
str
,
"type of row[0] must be unicode"
)
self
.
failUnless
(
row
[
0
].
endswith
(
"reich"
),
"column must contain original data"
)
def
CheckOptimizedUnicode
(
self
):
self
.
con
.
text_factory
=
sqlite
.
OptimizedUnicode
austria
=
str
(
"sterreich"
,
"latin1"
)
germany
=
str
(
"Deutchland"
)
austria
=
"sterreich"
germany
=
"Deutchland"
a_row
=
self
.
con
.
execute
(
"select ?"
,
(
austria
,)).
fetchone
()
d_row
=
self
.
con
.
execute
(
"select ?"
,
(
germany
,)).
fetchone
()
self
.
failUnless
(
type
(
a_row
[
0
])
==
str
,
"type of non-ASCII row must be unicode"
)
self
.
failUnless
(
type
(
d_row
[
0
])
==
str
,
"type of ASCII-only row must be str
"
)
self
.
failUnless
(
type
(
d_row
[
0
])
==
str
8
,
"type of ASCII-only row must be str8
"
)
def
tearDown
(
self
):
self
.
con
.
close
()
...
...
Lib/sqlite3/test/types.py
View file @
e7032b0d
...
...
@@ -62,7 +62,7 @@ class SqliteTypeTests(unittest.TestCase):
self
.
failUnlessEqual
(
row
[
0
],
val
)
def
CheckBlob
(
self
):
val
=
buffer
(
"Guglhupf"
)
val
=
buffer
(
b
"Guglhupf"
)
self
.
cur
.
execute
(
"insert into test(b) values (?)"
,
(
val
,))
self
.
cur
.
execute
(
"select b from test"
)
row
=
self
.
cur
.
fetchone
()
...
...
@@ -203,7 +203,7 @@ class DeclTypesTests(unittest.TestCase):
def
CheckBlob
(
self
):
# default
val
=
buffer
(
"Guglhupf"
)
val
=
buffer
(
b
"Guglhupf"
)
self
.
cur
.
execute
(
"insert into test(bin) values (?)"
,
(
val
,))
self
.
cur
.
execute
(
"select bin from test"
)
row
=
self
.
cur
.
fetchone
()
...
...
@@ -304,7 +304,7 @@ class BinaryConverterTests(unittest.TestCase):
self
.
con
.
close
()
def
CheckBinaryInputForConverter
(
self
):
testdata
=
"abcdefg"
*
10
testdata
=
b
"abcdefg"
*
10
result
=
self
.
con
.
execute
(
'select ? as "x [bin]"'
,
(
buffer
(
bz2
.
compress
(
testdata
)),)).
fetchone
()[
0
]
self
.
failUnlessEqual
(
testdata
,
result
)
...
...
Lib/sqlite3/test/userfunctions.py
View file @
e7032b0d
...
...
@@ -36,7 +36,7 @@ def func_returnfloat():
def
func_returnnull
():
return
None
def
func_returnblob
():
return
buffer
(
"blob"
)
return
buffer
(
b
"blob"
)
def
func_raiseexception
():
5
/
0
...
...
@@ -197,7 +197,7 @@ class FunctionTests(unittest.TestCase):
cur
.
execute
(
"select returnblob()"
)
val
=
cur
.
fetchone
()[
0
]
self
.
failUnlessEqual
(
type
(
val
),
buffer
)
self
.
failUnlessEqual
(
val
,
buffer
(
"blob"
))
self
.
failUnlessEqual
(
val
,
buffer
(
b
"blob"
))
def
CheckFuncException
(
self
):
cur
=
self
.
con
.
cursor
()
...
...
Modules/_sqlite/connection.c
View file @
e7032b0d
...
...
@@ -435,10 +435,8 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
}
else
if
(
PyString_Check
(
py_val
))
{
sqlite3_result_text
(
context
,
PyString_AsString
(
py_val
),
-
1
,
SQLITE_TRANSIENT
);
}
else
if
(
PyUnicode_Check
(
py_val
))
{
stringval
=
PyUnicode_AsUTF8String
(
py_val
);
if
(
stringval
)
{
sqlite3_result_text
(
context
,
PyString_AsString
(
stringval
),
-
1
,
SQLITE_TRANSIENT
);
Py_DECREF
(
stringval
);
sqlite3_result_text
(
context
,
PyUnicode_AsString
(
stringval
),
-
1
,
SQLITE_TRANSIENT
);
}
}
else
{
/* TODO: raise error */
...
...
@@ -1094,7 +1092,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto
finally
;
}
if
(
!
PyArg_ParseTuple
(
args
,
"O!O:create_collation(name, callback)"
,
&
Py
String
_Type
,
&
name
,
&
callable
))
{
if
(
!
PyArg_ParseTuple
(
args
,
"O!O:create_collation(name, callback)"
,
&
Py
Unicode
_Type
,
&
name
,
&
callable
))
{
goto
finally
;
}
...
...
Modules/_sqlite/cursor.c
View file @
e7032b0d
...
...
@@ -248,7 +248,7 @@ PyObject* _pysqlite_build_column_name(const char* colname)
if
((
*
pos
==
'['
)
&&
(
pos
>
colname
)
&&
(
*
(
pos
-
1
)
==
' '
))
{
pos
--
;
}
return
Py
String
_FromStringAndSize
(
colname
,
pos
-
colname
);
return
Py
Unicode
_FromStringAndSize
(
colname
,
pos
-
colname
);
}
}
}
...
...
@@ -372,8 +372,10 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
}
}
else
if
(
self
->
connection
->
text_factory
==
(
PyObject
*
)
&
PyString_Type
)
{
converted
=
PyString_FromString
(
val_str
);
}
else
if
(
self
->
connection
->
text_factory
==
(
PyObject
*
)
&
PyBytes_Type
)
{
converted
=
PyBytes_FromStringAndSize
(
val_str
,
strlen
(
val_str
));
}
else
{
converted
=
PyObject_CallFunction
(
self
->
connection
->
text_factory
,
"
s
"
,
val_str
);
converted
=
PyObject_CallFunction
(
self
->
connection
->
text_factory
,
"
y
"
,
val_str
);
}
}
else
{
/* coltype == SQLITE_BLOB */
...
...
@@ -746,17 +748,13 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
return
NULL
;
}
if
(
PyString_Check
(
script_obj
))
{
script_cstr
=
PyString_AsString
(
script_obj
);
}
else
if
(
PyUnicode_Check
(
script_obj
))
{
script_str
=
PyUnicode_AsUTF8String
(
script_obj
);
if
(
!
script_str
)
{
if
(
PyUnicode_Check
(
script_obj
))
{
script_cstr
=
PyUnicode_AsString
(
script_obj
);
if
(
!
script_cstr
)
{
return
NULL
;
}
script_cstr
=
PyString_AsString
(
script_str
);
}
else
{
PyErr_SetString
(
PyExc_ValueError
,
"script argument must be unicode
or string
."
);
PyErr_SetString
(
PyExc_ValueError
,
"script argument must be unicode."
);
return
NULL
;
}
...
...
Modules/_sqlite/row.c
View file @
e7032b0d
...
...
@@ -86,8 +86,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
item
=
PyTuple_GetItem
(
self
->
data
,
_idx
);
Py_XINCREF
(
item
);
return
item
;
}
else
if
(
Py
String
_Check
(
idx
))
{
key
=
Py
String
_AsString
(
idx
);
}
else
if
(
Py
Unicode
_Check
(
idx
))
{
key
=
Py
Unicode
_AsString
(
idx
);
nitems
=
PyTuple_Size
(
self
->
description
);
...
...
Modules/_sqlite/statement.c
View file @
e7032b0d
...
...
@@ -113,7 +113,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
rc
=
sqlite3_bind_text
(
self
->
st
,
pos
,
string
,
-
1
,
SQLITE_TRANSIENT
);
}
else
if
PyUnicode_Check
(
parameter
)
{
stringval
=
PyUnicode_AsUTF8String
(
parameter
);
string
=
PyString_AsString
(
stringval
);
string
=
PyBytes_AsString
(
stringval
);
rc
=
sqlite3_bind_text
(
self
->
st
,
pos
,
string
,
-
1
,
SQLITE_TRANSIENT
);
Py_DECREF
(
stringval
);
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment