Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-10

Generate a string with a record of SQLite3 database

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Usuario Anónimo

Hello, I have a SQLite3 database and I want to send the records by lNet components.

I need to create a string from the fields of the table.

I have this:

  with DataModule1.Db do
    begin
      TableName := 'Item';
      if not TableExists then
      begin
        FieldDefs.Clear;
        FieldDefs.Add('Code',ftAutoInc); // ftAutoInc con ftString hce falta
establecer una clave primaria PrimaryKey := 'Code';
        FieldDefs.Add('Description',ftString);
        FieldDefs.Add('Stock',ftBoolean);
        CreateTable;
      end;
    end;

records:
1, Description1, False
2, Description2, False
3, Description3, True

and I want to create a string, for example:

1#Description1#False

to send this by lNet.

I do this:

sequence := Db.FieldValues['Code'] + '#' <'@'> +
                   Db.FieldValues['Proveedor'] + '#' <'@'> +
                   Db.FieldValues['Almacen'] + '#' <'@'> +
                   Db.FieldValues['Unidades'];

but I get the following error: Project raised exception class 'RunError(231)'.

Two things:

1.- Which is the correct form to generate the string? 2.- It is necessary to beforehand know the name the fields to generate the string?

I want something like this:

for i:= 1 to Db.FieldCount do
  Db.FieldValues[i];

Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081001/b8ee1ae2/attachment.html

Reply by email

Joost van der Sluis
to Usuario Anónimo

Op woensdag 01-10-2008 om 17:06 uur [tijdzone +0200], schreef Usuario An?nimo:

sequence := Db.FieldValues['Code'] + '#' + Db.FieldValues['Proveedor'] + '#' + Db.FieldValues['Almacen'] + '#' + Db.FieldValues['Unidades'];

Please don't use the FieldValues property. I didn't even knew that property existed until recently. But afaik your code should work with fpc 2.2.2 or maybe 2.3.1. If not, please create a bug-report.

But in the general case, use Db.FieldByName('Proveedor').AsString. That's faster and you avoid the use of variants. If you do need a variant, use Db.FieldByName.Value.

I want something like this: for i:= 1 to Db.FieldCount do Db.FieldValues[i];
for i := 0 to Db.Fieldcount -1 do
  writeln(db.fields[0].AsString);

Joost

Reply by email

Joost van der Sluis
to Usuario Anónimo: Hello, I have a SQLite3 database and I want to send the records by lNet components. I…

Op woensdag 01-10-2008 om 17:06 uur [tijdzone +0200], schreef Usuario An?nimo:

sequence := Db.FieldValues['Code'] + '#' + Db.FieldValues['Proveedor'] + '#' + Db.FieldValues['Almacen'] + '#' + Db.FieldValues['Unidades'];

btw: Where did you get the idea to use FieldValues from? I don't know anybody using it? Did you find it somewhere on the net, or did you found it out yourselve? (Using ideas from other program-languages?)

Joost.

Reply by email

Usuario Anónimo
to Joost van der Sluis

I put Db. and the code completion show it. I am beginner.

Regards.

PD: Thank you very much, your solution is very good!

2008/10/1 Joost van der Sluis

Show quoted text 19 lines
Op woensdag 01-10-2008 om 17:06 uur [tijdzone +0200], schreef Usuario An?nimo: > sequence := Db.FieldValues['Code'] + '#' + > Db.FieldValues['Proveedor'] + '#' + > Db.FieldValues['Almacen'] + '#' + > Db.FieldValues['Unidades']; btw: Where did you get the idea to use FieldValues from? I don't know anybody using it? Did you find it somewhere on the net, or did you found it out yourselve? (Using ideas from other program-languages?) Joost. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081001/7222793d/attachment.html

Reply by email

Inoussa OUEDRAOGO
to Joost van der Sluis: Op woensdag 01-10-2008 om 17:06 uur [tijdzone +0200], schreef Usuario An?nimo: btw: Where…
btw: Where did you get the idea to use FieldValues from? I don't know anybody using it? Did you find it somewhere on the net, or did you found it out yourselve? (Using ideas from other program-languages?)

"FieldValues" is an old property of TDataset, so it seems to me that it is a rather
used one. I for one use it regularly in Delphi code.

Inoussa O.

Reply by email