1
1
# cursor description
2
2
from datetime import datetime , date
3
3
from pytest import mark
4
+ import duckdb
4
5
5
6
6
7
class TestCursorDescription (object ):
7
8
@mark .parametrize (
8
9
"query,column_name,string_type,real_type" ,
9
10
[
10
- ["SELECT * FROM integers" , "i" , "NUMBER " , int ],
11
- ["SELECT * FROM timestamps" , "t" , "DATETIME " , datetime ],
12
- ["SELECT DATE '1992-09-20' AS date_col;" , "date_col" , "Date " , date ],
13
- ["SELECT '\\ xAA'::BLOB AS blob_col;" , "blob_col" , "BINARY " , bytes ],
14
- ["SELECT {'x': 1, 'y': 2, 'z': 3} AS struct_col" , "struct_col" , "dict " , dict ],
15
- ["SELECT [1, 2, 3] AS list_col" , "list_col" , "list " , list ],
16
- ["SELECT 'Frank' AS str_col" , "str_col" , "STRING " , str ],
11
+ ["SELECT * FROM integers" , "i" , "INTEGER " , int ],
12
+ ["SELECT * FROM timestamps" , "t" , "TIMESTAMP " , datetime ],
13
+ ["SELECT DATE '1992-09-20' AS date_col;" , "date_col" , "DATE " , date ],
14
+ ["SELECT '\\ xAA'::BLOB AS blob_col;" , "blob_col" , "BLOB " , bytes ],
15
+ ["SELECT {'x': 1, 'y': 2, 'z': 3} AS struct_col" , "struct_col" , "STRUCT(x INTEGER, y INTEGER, z INTEGER) " , dict ],
16
+ ["SELECT [1, 2, 3] AS list_col" , "list_col" , "INTEGER[] " , list ],
17
+ ["SELECT 'Frank' AS str_col" , "str_col" , "VARCHAR " , str ],
17
18
["SELECT [1, 2, 3]::JSON AS json_col" , "json_col" , "JSON" , str ],
18
19
["SELECT union_value(tag := 1) AS union_col" , "union_col" , "UNION(tag INTEGER)" , int ],
19
20
],
@@ -23,6 +24,24 @@ def test_description(self, query, column_name, string_type, real_type, duckdb_cu
23
24
assert duckdb_cursor .description == [(column_name , string_type , None , None , None , None , None )]
24
25
assert isinstance (duckdb_cursor .fetchone ()[0 ], real_type )
25
26
27
+ def test_description_comparisons (self ):
28
+ duckdb .execute ("select 42 a, 'test' b, true c" )
29
+ types = [x [1 ] for x in duckdb .description ()]
30
+
31
+ STRING = duckdb .STRING
32
+ NUMBER = duckdb .NUMBER
33
+ DATETIME = duckdb .DATETIME
34
+
35
+ assert (types [1 ] == STRING )
36
+ assert (STRING == types [1 ])
37
+ assert (types [0 ] != STRING )
38
+ assert ((types [1 ] != STRING ) == False )
39
+ assert ((STRING != types [1 ]) == False )
40
+
41
+ assert (types [1 ] in [STRING ])
42
+ assert (types [1 ] in [STRING , NUMBER ])
43
+ assert (types [1 ] not in [NUMBER , DATETIME ])
44
+
26
45
def test_none_description (self , duckdb_empty_cursor ):
27
46
assert duckdb_empty_cursor .description is None
28
47
0 commit comments