 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ciaran Costelloe Guest
|
Posted: Sun Jan 08, 2006 9:23 pm Post subject: Primary key problems |
|
|
I am trying to create a table with a primary key based on the first two
fields by sending the following SQL through a TSQLConnection to a
Firebird database via an Interbase driver, but it fails:
"CREATE TABLE SINDEX (ALIASUPPER VARCHAR(211) NOT NULL PRIMARY
KEY,REPETITN SMALLINT NOT NULL PRIMARY KEY,ALIAAS VARCHAR(211),RECORDNO
INTEGER)"
I get an error rather than success, but I cannot determine the exact
error because I have messed up some DLL in trying to get various
connections working, so I just get exceptions "No mapping for error
code found" (in all other respects, my Interbase driver appears to be
fine). Using a primary key on one field works fine (but I cannot use
this in practice because the first field is not unique):
"CREATE TABLE SINDEX (ALIASUPPER VARCHAR(211) NOT NULL PRIMARY
KEY,REPETITN SMALLINT,ALIAAS VARCHAR(211),RECORDNO INTEGER)"
I can also create it with no primary index and add an index on the
first field (which is how I will be accessing it) but I try to avoid
this, as it caused me major performance problems with Paradox.
Anyway, the question is whether my SQL command is wrong in some respect?
Thanks in advance for any help,
Ciaran
|
|
| Back to top |
|
 |
ssamayoa Guest
|
Posted: Mon Jan 09, 2006 4:08 pm Post subject: Re: Primary key problems |
|
|
The problem is simple: multi column primary key arent specified as you did.
the correct would be:
"CREATE TABLE SINDEX (ALIASUPPER VARCHAR(211) NOT NULL,REPETITN SMALLINT
NOT NULL ,ALIAAS VARCHAR(211),RECORDNO
INTEGER, PRIMARY KEY (ALIASUPPER, REPETITN))"
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
Ciaran Costelloe Guest
|
Posted: Mon Jan 09, 2006 11:10 pm Post subject: Re: Primary key problems |
|
|
ssamayoa wrote:
| Quote: | "CREATE TABLE SINDEX (ALIASUPPER VARCHAR(211) NOT NULL,REPETITN
SMALLINT NOT NULL ,ALIAAS VARCHAR(211),RECORDNO
INTEGER, PRIMARY KEY (ALIASUPPER, REPETITN))"
|
Thanks very much for the reply. My apologies, I should have stated
that I had previously tried that method, but it did not work either
(TSQLConnection returns success, but the table is not created - weird).
I recoded and tried it again, but it is still the same :-(
Thanks anyway,
Ciaran
|
|
| Back to top |
|
 |
Thomas Miller Guest
|
Posted: Tue Jan 10, 2006 4:31 pm Post subject: Re: Primary key problems |
|
|
Did you issue a commit after that?
Ciaran Costelloe wrote:
| Quote: | ssamayoa wrote:
"CREATE TABLE SINDEX (ALIASUPPER VARCHAR(211) NOT NULL,REPETITN
SMALLINT NOT NULL ,ALIAAS VARCHAR(211),RECORDNO
INTEGER, PRIMARY KEY (ALIASUPPER, REPETITN))"
Thanks very much for the reply. My apologies, I should have stated
that I had previously tried that method, but it did not work either
(TSQLConnection returns success, but the table is not created - weird).
I recoded and tried it again, but it is still the same :-(
Thanks anyway,
Ciaran
|
--
Thomas Miller
Chrome Portal Project Manager
Wash DC Delphi SIG Chairperson
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork
http://www.bss-software.com
http://www.cpcug.org/user/delphi/index.html
http://sourceforge.net/projects/chromeportal/
http://sourceforge.net/projects/uopl/
http://sourceforge.net/projects/dbexpressplus
|
|
| Back to top |
|
 |
Ciaran Costelloe Guest
|
Posted: Tue Jan 10, 2006 8:40 pm Post subject: Re: Primary key problems |
|
|
Thomas Miller wrote:
| Quote: | Did you issue a commit after that?
|
No, because I did not think I needed to. I will try that out.
I have not being using commits at all, because I thought they were only
used in transactions - am I implicitly opening a transaction somehow?
Thanks very much for the pointer.
Ciaran
|
|
| Back to top |
|
 |
Thomas Miller Guest
|
Posted: Tue Jan 10, 2006 9:48 pm Post subject: Re: Primary key problems |
|
|
Yes and no. It could be a bug in the driver as this is a DDL statement
and works a bit differently. Also, Firebird doesn't auto commit DDL
statements like many other DBs.
Just send a second statement to the server with 'COMMIT' as the only item.
The http://www.upscene.com drive use to have this "bug", but works fine
now.
Ciaran Costelloe wrote:
| Quote: | Thomas Miller wrote:
Did you issue a commit after that?
No, because I did not think I needed to. I will try that out.
I have not being using commits at all, because I thought they were only
used in transactions - am I implicitly opening a transaction somehow?
Thanks very much for the pointer.
Ciaran
|
--
Thomas Miller
Chrome Portal Project Manager
Wash DC Delphi SIG Chairperson
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork
http://www.bss-software.com
http://www.cpcug.org/user/delphi/index.html
http://sourceforge.net/projects/chromeportal/
http://sourceforge.net/projects/uopl/
http://sourceforge.net/projects/dbexpressplus
|
|
| Back to top |
|
 |
Ciaran Costelloe Guest
|
Posted: Tue Jan 10, 2006 11:23 pm Post subject: Re: Primary key problems |
|
|
Thomas Miller wrote:
| Quote: | Just send a second statement to the server with 'COMMIT' as the only
item.
|
Thanks Thomas. I tried it but it did not work.
Since what I am trying is obviously not totally stupid, it is
presumably a bug somewhere: I can work around it for the moment by
adding a "record number" field and using that as the Primary Key and
adding an index on the two existing fields, which does execute properly.
The bug should disappear, as I am awaiting delivery of D2006 Enterprise
(which may help sort out my DLL problems), plus I will be using a later
Firebird version on a different box.
I was really afraid my lack of SQL knowledge was the problem, thanks to
you both for the benefit of your wisdom.
Ciaran
|
|
| Back to top |
|
 |
ssamayoa Guest
|
Posted: Wed Jan 11, 2006 4:44 pm Post subject: Re: Primary key problems |
|
|
What is the exact error message?
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
Ciaran Costelloe Guest
|
Posted: Thu Jan 12, 2006 12:04 am Post subject: Re: Primary key problems |
|
|
ssamayoa wrote:
| Quote: | What is the exact error message?
|
I cannot get any error messages because I have some problem with my
mixture of DLLs, I just get exceptions "No mapping for error code
found" (I do get a success or fail return code, however) - there is a
bit more info on this in my first post, and I am hoping that D2006 will
sort that out, when I get it.
Anyway, I think I have found out a bit more about this, and it appears
to be just a one-off issue: I changed the table structure and used a
"record number" field and used that as the primary key, and had no
problem creating the table. I then added two additional indexes, one
on the ALIASUPPER field and one the two fields I originally had as the
primary keys, ALIAS and REPETITION - while no error was reported on
creating either index, only the first one was created, the same as what
I experienced with CREATE TABLE.
I need to explain more at this point. All the SQL is being generated
dynamically by a class that I have written. The curious bit is that
the same code has no problem creating indexes with two fields on other
tables.
The problem may be down to the field names I am using - this previously
occured to me, so I tried names of ALIAAS instead of ALIAS and REPETITN
instead of REPETITION, but it is possible that I did not code this
correctly somewhere or that the ALIASUPPER field name, or the SINDEX
table name, is the problem. It may be that the Firebird server parses
the SQL request and finds no problem, and then sends back a success
response, but it subsequently hits a problem preventing it creating the
index.
Anyway, it looks like a one-off issue rather than a general problem, I
will post back if I can find exactly what the issue is.
Ciaran
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|