11# cursor description
22from datetime import datetime , date
33from pytest import mark
4+ import duckdb
45
56
67class TestCursorDescription (object ):
78 @mark .parametrize (
89 "query,column_name,string_type,real_type" ,
910 [
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 ],
1718 ["SELECT [1, 2, 3]::JSON AS json_col" , "json_col" , "JSON" , str ],
1819 ["SELECT union_value(tag := 1) AS union_col" , "union_col" , "UNION(tag INTEGER)" , int ],
1920 ],
@@ -23,6 +24,24 @@ def test_description(self, query, column_name, string_type, real_type, duckdb_cu
2324 assert duckdb_cursor .description == [(column_name , string_type , None , None , None , None , None )]
2425 assert isinstance (duckdb_cursor .fetchone ()[0 ], real_type )
2526
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+
2645 def test_none_description (self , duckdb_empty_cursor ):
2746 assert duckdb_empty_cursor .description is None
2847
0 commit comments