Until 10 years ago, I was an active Delphi programmer. I was a Novell Engineer and wrote utilities to assist me with my work.
The last time I wrote any code was in 2003 and now I'm retired and I got bored so decided to start writing some code again. Alas, a 10 years break and a 72 year old brain and I'm back to 'newbie' status.
I downloaded Zeoslib and managed to create a database and a table, but I couldn't work out how to create a primary key!
Then horror of horrors, I've completely forgotten how to append records to the database. I've never used Zeoslib before, I used to have Microolap's DAC for MySQL, (that was when i had money!).
I'm ashamed to ask, but would someone please tell me how to create a primary key at runtime and how to add records to the Table. An example would be nice!
Newbie question!
Moderators: gto, cipto_kh, EgonHugeist
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Hello Baldur 2630,
I am not used to MySQL this is what the manual says:
http://dev.mysql.com/doc/refman/5.1/de/alter-table.html
So this should translate to some sql like
alter table mytable add constraint PK_mytable PRIMARY KEY (mycol1, mycol2);
But usually I would think about adding the primary key when designing the database using the design tool like phpMyAdmin or a similar tool?
And as for your second question, generally this should look somewhat like this:
ZQuery.Close;
ZQuery.SQL.Text := 'select * from mytable';
ZQuery.Open;
ZQuery.Append;
ZQuery.FieldByName('mycol1').Value := x;
ZQuery.FieldByName('mycol2').Value := y;
ZQuery.Post;
Best regards,
Jan
I am not used to MySQL this is what the manual says:
http://dev.mysql.com/doc/refman/5.1/de/alter-table.html
So this should translate to some sql like
alter table mytable add constraint PK_mytable PRIMARY KEY (mycol1, mycol2);
But usually I would think about adding the primary key when designing the database using the design tool like phpMyAdmin or a similar tool?
And as for your second question, generally this should look somewhat like this:
ZQuery.Close;
ZQuery.SQL.Text := 'select * from mytable';
ZQuery.Open;
ZQuery.Append;
ZQuery.FieldByName('mycol1').Value := x;
ZQuery.FieldByName('mycol2').Value := y;
ZQuery.Post;
Best regards,
Jan
-
- Fresh Boarder
- Posts: 16
- Joined: 03.04.2013, 11:45
- Location: Belgium
The second part of your reply works perfectly. Thanks a lot for that. When I saw it, it slowly stated to come back . . . Log term memory definitely suffers as years advance. Once needs to keep the old brain in gear at all times!
I still didn't manage to create a Primary key, I'm working on it.
Thanks again. I have little doubt that 'I'll be back . . ."
I still didn't manage to create a Primary key, I'm working on it.
Thanks again. I have little doubt that 'I'll be back . . ."
-
- Fresh Boarder
- Posts: 16
- Joined: 03.04.2013, 11:45
- Location: Belgium
Thanks for the "brain starter pack!", The wheels are slowly starting to turn again, but still in first gear.
I managed to create the databases, create the tables, create Primary Keys and Indexes and the database seems to update OK (but I've only tested it with 2 or 3 entries).
I presume that with Zeoslib, before I end the program, I have to 'close' the databases and tables. Is this necessary, if so, how? In testing, I didn't close it, but all the data seems to be there.
I managed to create the databases, create the tables, create Primary Keys and Indexes and the database seems to update OK (but I've only tested it with 2 or 3 entries).
I presume that with Zeoslib, before I end the program, I have to 'close' the databases and tables. Is this necessary, if so, how? In testing, I didn't close it, but all the data seems to be there.
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
-
- Fresh Boarder
- Posts: 16
- Joined: 03.04.2013, 11:45
- Location: Belgium