Lazarus

Programming => Databases => Topic started by: madref on November 03, 2015, 10:53:46 pm

Title: [SOLVED] Writing floats to database
Post by: madref on November 03, 2015, 10:53:46 pm
i have the following table:
Code: [Select]

    cSQL := '';
    cSQL := cSQL + 'CREATE TABLE tbl_Divisie ';
    cSQL := cSQL + '(';
    cSQL := cSQL + 'Divisie_ID Word PRIMARY KEY ASC,';
    cSQL := cSQL + 'Divisie_Tekst varchar(25),';
    cSQL := cSQL + 'Divisie_Gebruiken Boolean,';
    cSQL := cSQL + 'Divisie_Volgorde Word,';
    cSQL := cSQL + 'Divisie_Voluit varchar(75),';
    cSQL := cSQL + 'Divisie_Vergoeding_Ref Float,';
    cSQL := cSQL + 'Divisie_Vergoeding_Lmn Float';
    cSQL := cSQL + ');';
    Connect_RefereeDB.ExecuteDirect(cSQL);
and now i am trying to write a record to this table with the following code:
Code: [Select]

    cSQL := '';
    cSQL := cSQL + 'INSERT INTO tbl_Divisies ';
    cSQL := cSQL + 'VALUES (1,"(All)",1,1,"All Divisions,0.0,0.0")';
    Connect_RefereeDB.ExecuteDirect(cSQL);
But the code gives an error with the floating points.
How can i write a floating point?
Title: Re: Writing floats to database
Post by: taazz on November 03, 2015, 10:58:37 pm
Code: [Select]

    cSQL := '';
    cSQL := cSQL + 'INSERT INTO tbl_Divisies ';
    cSQL := cSQL + 'VALUES (1,"(All)",1,1,"All Divisions,0.0,0.0")';
    Connect_RefereeDB.ExecuteDirect(cSQL);
But the code gives an error with the floating points.
How can i write a floating point?
take care where you end your strings in this case you need to move the double quote from the end of the line to the end of the Divisions word, see the highlighted line.
Code: Pascal  [Select][+][-]
  1.  
  2.     cSQL := '';
  3.     cSQL := cSQL + 'INSERT INTO tbl_Divisies ';
  4.     cSQL := cSQL + 'VALUES (1,"(All)",1,1,"All Divisions",0.0,0.0)';
  5.     Connect_RefereeDB.ExecuteDirect(cSQL);
  6.  
Title: Re: Writing floats to database
Post by: madref on November 03, 2015, 11:04:15 pm
I saw that error too...
But it still gives the same error.
it won't write my floats
Title: Re: Writing floats to database
Post by: taazz on November 03, 2015, 11:06:50 pm
I saw that error too...
But it still gives the same error.
it won't write my floats
post the complete error message. What you describe is not normal.
Title: Re: Writing floats to database
Post by: madref on November 03, 2015, 11:12:37 pm
The error is:
Project ..... raised exception class 'Unknown'.

And when i use the same construction in a different table it works like a charm.
Code: [Select]
    // tbl_Licenties_Keuze aanmaken
    cSQL := '';
    cSQL := cSQL + 'CREATE TABLE tbl_Licenties_Keuze ';
    cSQL := cSQL + '(';
    cSQL := cSQL + 'Licentie_ID Word PRIMARY KEY ASC,';
    cSQL := cSQL + 'Licentie varchar(10),';
    cSQL := cSQL + 'Licentie_Uitleg varchar(250)';
    cSQL := cSQL + ');';
    Connect_RefereeDB.ExecuteDirect(cSQL);
    // tbl_Licenties_Keuze vullen met de juiste licenties
    cSQL := '';
    cSQL := cSQL + 'INSERT INTO tbl_Licenties_Keuze ';
    cSQL := cSQL + 'VALUES (1,"-","Not applied for a License")';
    Connect_RefereeDB.ExecuteDirect(cSQL);
Title: Re: Writing floats to database
Post by: madref on November 03, 2015, 11:16:31 pm
I found the error. :)
I am creating a table called tbl_Divisie and i am trying to insert into tbl_DivisieS
Hence the error
TinyPortal © 2005-2018