"""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?
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?