Page 1 of 1

Table

Posted: Sun 25 Mar 2012 06:54
by secs
Guys I have a Delphi 7 program and I use a Mytable together with Myconnection. Now the database is some 300,000 records and rising some 8000 a day.

So does the Table component load the complete table when its active? All I do is add a record every 10 seconds to the table so if it is loading the complete table, can I do this some other way as the database is remote and takes a bit to fire up.

Peter

Posted: Mon 26 Mar 2012 08:39
by AndreyZ
Hello,

The TMyTable component stores all records that you add to it in the memory (it allows working with these records). To avoid this, you can directly execute INSERT SQL statements using the TMyQuery component. Here is an example:

Code: Select all

MyQuery.SQL.Text := 'INSERT INTO DEPT(DEPTNO, DNAME, LOC) VALUES(1, ''TESTNAME'', ''TESTLOC'')';
MyQuery.Execute;
using parameters:

Code: Select all

MyQuery.SQL.Text := 'INSERT INTO DEPT(DEPTNO, DNAME, LOC) VALUES(:deptno, :dname, :loc)';
MyQuery.ParamByName('deptno').AsInteger := 1;
MyQuery.ParamByName('dname').AsString := 'TESTNAME';
MyQuery.ParamByName('loc').AsString := 'TESTLOC';
MyQuery.Execute;

Posted: Wed 28 Mar 2012 01:55
by secs
Thanks heaps. I will edit the program and give it a go.
Peter

Posted: Wed 28 Mar 2012 12:25
by AndreyZ
If any other questions come up, please contact us.

Re: Table

Posted: Sat 28 Apr 2012 01:39
by secs
I finally have found enough time to sit down and attack the problem. I guess this may really be a SQL statement problem and I am off searching google but:

I have 2 fields in the database that are an interger filed that auto incroments simply used as an ID and another field thats a time stamp

I am preaty sure I have to include these fields in the statement t get the correct number of fields but what do I do as a value? I seem to remember I can use NIL or NUll or something...

Peter

Re: Table

Posted: Sat 28 Apr 2012 12:47
by AlexP
hello,

If there are autoincrement fields in the table, or there are fields that have a default value, than such fields do not need to be specified in the fields list of the INSERT command, i.e. for the table

Code: Select all

CREATE TABLE dept(
  DEPTNO INT(11) NOT NULL AUTO_INCREMENT,
  DNAME VARCHAR(14) DEFAULT NULL,
  LOC VARCHAR(13) DEFAULT NULL
)
it is enough to call the following operator INSERT

Code: Select all

MyQuery.SQL.Text := 'INSERT INTO DEPT(DNAME, LOC) VALUES( ''TESTNAME'', ''TESTLOC'')';
the DEPTNO field will be filled in automatically

Re: Table

Posted: Sat 28 Apr 2012 17:47
by secs
Thanks for that. I have it up and running. Will check the database to make sure its adding info but no errors etc so lets see.

Pete