Topic: Create multiple records at once

Hi

I have a user form where I can choose what part of a car will be dismantled (checkboxes).
Lets say that I choose 3 parts. The starter, the alternator and the fuel pump.

I want to create 3 records at once, one for each product. I wll later edit each record to input more metadata.

What script should I use to accomplish this?

Finally what language is used in MVD and what book can I use to learn this language?

Thank you
George

Re: Create multiple records at once

Hello.


Check out this example
http://myvisualdatabase.com/forum/viewt … 802#p33802

Dmitry.

Re: Create multiple records at once

Thank you.

I managed to accomplish what I wanted following this : http://myvisualdatabase.com/forum/viewtopic.php?id=2722

Now I want to find a way to loop through all the records of a table and create another table with additional data.
For example:

I have a table with two fields Name, Surname.
I want to loop through all the records and create another table with fields Name2,Surname2

Name2,Surname2 will contain data from initial Name and Surname fileds but they will be modified by a script to contain additional information.

Can you please help me on how to do the following tasks with scripts:
1. loop through all records
2. save Name2 and Surname2 data to a different table

Thank you
George

Re: Create multiple records at once

Example

procedure Form1_Button5_OnClick (Sender: TObject; var Cancel: boolean);
var
    Results: TDataSet;
    s1, s2: string;
begin
    SQLExecute('PRAGMA synchronous = OFF'); // to increase speed of INSERTs

    try
        SQLQuery('SELECT firstname, lastname FROM person', Results);
        while not Results.Eof do
        begin
            s1 := Results.FieldByName('firstname').asString;
            s2 := Results.FieldByName('lastname').asString;
            if s1 <> '' then s1 := '''' + escape_special_characters(s1) + '''' else s1 := 'NULL';
            if s2 <> '' then s2 := '''' + escape_special_characters(s2) + '''' else s2 := 'NULL';

            SQLExecute('INSERT INTO person_ (firstname, lastname) VALUES ('+s1+','+s2+')'); // here you can add additional information to "person_"

            Results.Next;
        end;
    finally
        SQLExecute('PRAGMA synchronous = FULL');
    end;
end;
Dmitry.

Re: Create multiple records at once

Thank you for the script code. I will try it and post back.

Regards
George

Re: Create multiple records at once

I have run the above code having made some changes to correspond to my tables and fields.

The while loop does not exit even after having reached the end of the file. It continuesly loops.

Any suggestions?

Thanks

Re: Create multiple records at once

Sorry my mistake. Everything is ok.

Re: Create multiple records at once

The problem was the sql update statement.

I am trying to change the value of a field in a table based on a certain criterion.
I scroll through all the records checking that a specific field has a specific value. If it has then I want to update the value of another field of the same record. Example:

Record has 3 fields. All records belong to the same table.

f1,f2,f3

I read each record and check if f1 is equal to 1. If it is I want to update the field f3 of this record with a new value , lets say f3:='yes'
I want to do this for all the records in the table.

How can I update the current record that I have selected with the updata statement. What do I put in the 'where' clause?

Thank you

Re: Create multiple records at once

Just run this SQL query for the table

SQLExecute('UPDATE tablename SET f3=''yes'' WHERE f1=1');
Dmitry.

Re: Create multiple records at once

Thnak you for your reply.

I did not mention that f1 is not a unique field. It is not a primary key.
One way is to include a field that is unique and then execute the statement above and reffering the WHERE clause to this field .

The question was (better stated): how can i edit and update the fields of a record when the table does not have a primary key?

Can I request from the database to give me the record id for the record I am editing? If yes then can I use this reply to issue an sql update statement for the same record?

Thanks again
George