Recent

Author Topic: Add code SQL in the class method  (Read 485 times)

carlos_am_2003

  • Newbie
  • Posts: 3
Add code SQL in the class method
« on: November 21, 2022, 01:15:49 pm »
Hello!
I have a class, for example, TCar and I need to save the data of the class TCar to any database.

Code: Pascal  [Select][+][-]
  1. TCar = class
  2. private
  3. name: string;
  4. year : integer;
  5. end
  6.  

How can I add code to save an object TCar in the database?

Code: Pascal  [Select][+][-]
  1. TCar = class
  2. private
  3. name: string;
  4. year : integer;
  5. procedude SQL_InsertOrUpdate;
  6. procedude SQL_Delete;
  7. end
  8.  

OR

Code: Pascal  [Select][+][-]
  1. TCar = class
  2. private
  3. name: string;
  4. year : integer;
  5. end;
  6. TSQL_Car = class
  7. procedure SQL_InsertOrUpdate(car : TCar);
  8. procedude SQL_Delete(car : TCar);
  9.  

What do you think?

Help me!

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Add code SQL in the class method
« Reply #1 on: November 21, 2022, 02:30:57 pm »
Do you have code using SQL at all? That's not in a class? that works?

Because right now, i don't get it, what the problem is
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Add code SQL in the class method
« Reply #2 on: November 21, 2022, 02:50:23 pm »
I think he's looking for a way to serialise an instance into a table.

Deserialisation costs extra :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

carlos_am_2003

  • Newbie
  • Posts: 3
Re: Add code SQL in the class method
« Reply #3 on: November 21, 2022, 03:12:16 pm »
Hi!

I would just like an opinion on the best way to go about it.

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Add code SQL in the class method
« Reply #4 on: November 21, 2022, 03:15:54 pm »
How about reading the documentation?
https://wiki.freepascal.org/SQLdb_Programming_Reference

I'd start with "How to set up the SQL-Trinity" (Connection-, Transaction-, Query-Objects)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018