Page 1 of 1

Newbie question!

Posted: 03.04.2013, 11:56
by Baldur2630
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!
:cry:

Posted: 04.04.2013, 08:54
by marsupilami
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

Posted: 04.04.2013, 22:05
by Baldur2630
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 . . ."

Posted: 06.04.2013, 10:28
by Baldur2630
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.

Posted: 09.04.2013, 12:07
by marsupilami
Hello Baldur2630,

if you don't close the connection explicitly it will close down itself when it gets destroyed by the destruction of the form, I guess. I prefer to close it down myself.
Best regards,

Jan

Posted: 30.04.2013, 14:24
by Baldur2630
Thanks for all the help. I managed to Create the database, Create all the tables, Indexes, Constraints, References. Foreign Keys etc. at Runtime. I spent a lot of time trying to work this out, but I finally got it all working. NOT easy!

Now for the next problem . . .