Recent

Author Topic: [SOLVED] Writing floats to database  (Read 2572 times)

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[SOLVED] Writing floats to database
« 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?
« Last Edit: November 03, 2015, 11:17:01 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Writing floats to database
« Reply #1 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.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Writing floats to database
« Reply #2 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
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Writing floats to database
« Reply #3 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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Writing floats to database
« Reply #4 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);
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Writing floats to database
« Reply #5 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
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

 

TinyPortal © 2005-2018