opus49 / py3odb

Python 3.6+ compatible interface to ECMWF's ODB API
MIT License
1 stars 0 forks source link

use py3odb #6

Open NWPC-Whisperer opened 4 years ago

NWPC-Whisperer commented 4 years ago

I execute the following code:

import py3odb

TEST_DATA = ( (3, 1.2, 'apple', 1), (49, 3.14159, 'pie', 2), (-12, -0.0003, 'longer_than_8_characters', 3) )

"""Create a database and then read from it.""" db_file = "temp.odb"

create a database

conn = py3odb.connect("") cur = conn.cursor() cur.execute( "CREATE TABLE t_foo AS (a INTEGER, b REAL, c STRING, d BITFIELD) " f"ON '{db_file}'" ) cur.executemany("INSERT INTO t_foo(a,b,c,d) VALUES(?,?,?,?)", TEST_DATA) conn.close()

Here,can be generated correctly the file temp.odb.

read from it

conn = py3odb.connect(f"{db_file}") cur = conn.cursor() cur.execute(f"SELECT * FROM '{db_file}'") print(cur)

Here, print <py3odb.cursor.Cursor object at 0x7f1fc83def90>

But when use this code to obtain the context, an error occurred. for row in cur: print(f"Fetched row: {row}")

it occur "[1] 14979 segmentation fault (core dumped) python ex1.py".

I want to ask why does this happen? How to solve it?

opus49 commented 4 years ago

I cannot reproduce your error.

NWPC-Whisperer commented 4 years ago

I cannot reproduce your error.

Thank you. It' s prove that the code is correct. I use win10 Linux subsystem,may be some environmental issues.