@@ -104,3 +104,60 @@ func TestDBWithParquetSession(t *testing.T) {
104104 count ++
105105 }
106106}
107+
108+ func TestDBWithParquetConnection (t * testing.T ) {
109+ connectionDir , err := os .MkdirTemp ("" , "unittest-connectiondata" )
110+ if err != nil {
111+ t .Fatalf ("create temp directory fail, err: %s" , err )
112+ }
113+ defer os .RemoveAll (connectionDir )
114+ connection , err := chdb .NewConnection (connectionDir )
115+ if err != nil {
116+ t .Fatalf ("new connection fail, err: %s" , err )
117+ }
118+ defer connection .Cleanup ()
119+
120+ connection .Query ("CREATE DATABASE IF NOT EXISTS testdb; " +
121+ "CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;" )
122+
123+ connection .Query ("INSERT INTO testdb.testtable VALUES (1), (2), (3);" )
124+
125+ ret , err := connection .Query ("SELECT * FROM testdb.testtable;" )
126+ if err != nil {
127+ t .Fatalf ("Query fail, err: %s" , err )
128+ }
129+ if string (ret .Buf ()) != "1\n 2\n 3\n " {
130+ t .Errorf ("Query result should be 1\n 2\n 3\n , got %s" , string (ret .Buf ()))
131+ }
132+ db , err := sql .Open ("chdb" , fmt .Sprintf ("connection=file:%s/chdb.db;driverType=%s" , connectionDir , "PARQUET" ))
133+ if err != nil {
134+ t .Fatalf ("open db fail, err: %s" , err )
135+ }
136+ if db .Ping () != nil {
137+ t .Fatalf ("ping db fail, err: %s" , err )
138+ }
139+ rows , err := db .Query ("select * from testdb.testtable;" )
140+ if err != nil {
141+ t .Fatalf ("exec create function fail, err: %s" , err )
142+ }
143+ defer rows .Close ()
144+ cols , err := rows .Columns ()
145+ if err != nil {
146+ t .Fatalf ("get result columns fail, err: %s" , err )
147+ }
148+ if len (cols ) != 1 {
149+ t .Fatalf ("result columns length shoule be 3, actual: %d" , len (cols ))
150+ }
151+ var bar = 0
152+ var count = 1
153+ for rows .Next () {
154+ err = rows .Scan (& bar )
155+ if err != nil {
156+ t .Fatalf ("scan fail, err: %s" , err )
157+ }
158+ if bar != count {
159+ t .Fatalf ("result is not match, want: %d actual: %d" , count , bar )
160+ }
161+ count ++
162+ }
163+ }
0 commit comments