Subject | RE: [ib-support] primary key not enforced after recreating the table |
---|---|
Author | Louis Kleiman |
Post date | 2002-12-05T19:07:27Z |
I dont know PHP, but it looks like the following statement should fail
on the second execution:
cur.execute("INSERT INTO T1 VALUES (?,?)", (1,''))
because you are trying to insert the same record every time with the
values 1 and .
Perhaps you mean to insert I and ''.
Again, I am very ignorant of your environment, but this stuck out at me
as being a possible problem.
Louis Kleiman
SSTMS, Inc.
-----Original Message-----
From: David Garamond [mailto:davegaramond@...]
Sent: Thursday, December 05, 2002 11:58 AM
To: ib-support@yahoogroups.com
Subject: [ib-support] primary key not enforced after recreating the
table
(FirebirdCS-1.0.0.796-0 running as user 'firebird', redhat 7.2 on i386
(AMD Duron), kinterbasdb 3.0.2, python 2.2.2, perl 5.8.0, DBD::InterBase
0.40.)
first i create an empty database using isql, and then chgrp it so the
'firebird' user can write to it. then i run the following python code
(which basically [re]create a simple table and fill it with 20,000
rows):
import sys
def p(s): print s; sys.stdout.flush()
p("Connecting...")
con = kinterbasdb.connect(
dsn="localhost:/home/david/1.gdb",
user="sysdba",
password="pass"
)
cur = con.cursor()
p("Recreating table...")
try: cur.execute("DROP TABLE T1")
except kinterbasdb.ProgrammingError: cur=con.cursor()
cur.execute("CREATE TABLE T1 (i INT NOT NULL PRIMARY KEY, s
VARCHAR(250))")
con.commit()
p("Inserting...")
for i in range(20000):
cur.execute("INSERT INTO T1 VALUES (?,?)", (1,''))
p("Committing...")
con.commit()
<<<
and execution fails at the second row insert because of the integrity
constraint: 'violation of PRIMARY or UNIQUE KEY constraint "INTEG_2" on
table "T1"'. the program exits. when i check with isql, T1 is empty as
expected as the first insert was rolled back.
then i run the program again. this time, all rows are inserted
successfully! after the program completes, i check with isql. there is
20,000 records, each with i=1. 'USE INDICES' shows:
RDB$PRIMARY2 UNIQUE INDEX ON T1(I)
so the PK index is still there. (right?)
i wrote an equivalent perl script using DBD::InterBase, and it produces
the same thing.
is this normal? what should i do to enforce PK? i'm baffled.
--
dave
Yahoo! Groups Sponsor
ADVERTISEMENT
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
on the second execution:
cur.execute("INSERT INTO T1 VALUES (?,?)", (1,''))
because you are trying to insert the same record every time with the
values 1 and .
Perhaps you mean to insert I and ''.
Again, I am very ignorant of your environment, but this stuck out at me
as being a possible problem.
Louis Kleiman
SSTMS, Inc.
-----Original Message-----
From: David Garamond [mailto:davegaramond@...]
Sent: Thursday, December 05, 2002 11:58 AM
To: ib-support@yahoogroups.com
Subject: [ib-support] primary key not enforced after recreating the
table
(FirebirdCS-1.0.0.796-0 running as user 'firebird', redhat 7.2 on i386
(AMD Duron), kinterbasdb 3.0.2, python 2.2.2, perl 5.8.0, DBD::InterBase
0.40.)
first i create an empty database using isql, and then chgrp it so the
'firebird' user can write to it. then i run the following python code
(which basically [re]create a simple table and fill it with 20,000
rows):
>>>import kinterbasdb
import sys
def p(s): print s; sys.stdout.flush()
p("Connecting...")
con = kinterbasdb.connect(
dsn="localhost:/home/david/1.gdb",
user="sysdba",
password="pass"
)
cur = con.cursor()
p("Recreating table...")
try: cur.execute("DROP TABLE T1")
except kinterbasdb.ProgrammingError: cur=con.cursor()
cur.execute("CREATE TABLE T1 (i INT NOT NULL PRIMARY KEY, s
VARCHAR(250))")
con.commit()
p("Inserting...")
for i in range(20000):
cur.execute("INSERT INTO T1 VALUES (?,?)", (1,''))
p("Committing...")
con.commit()
<<<
and execution fails at the second row insert because of the integrity
constraint: 'violation of PRIMARY or UNIQUE KEY constraint "INTEG_2" on
table "T1"'. the program exits. when i check with isql, T1 is empty as
expected as the first insert was rolled back.
then i run the program again. this time, all rows are inserted
successfully! after the program completes, i check with isql. there is
20,000 records, each with i=1. 'USE INDICES' shows:
RDB$PRIMARY2 UNIQUE INDEX ON T1(I)
so the PK index is still there. (right?)
i wrote an equivalent perl script using DBD::InterBase, and it produces
the same thing.
is this normal? what should i do to enforce PK? i'm baffled.
--
dave
Yahoo! Groups Sponsor
ADVERTISEMENT
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.