NO

Author Topic: Working with databases  (Read 5460 times)

Zodra1

  • Guest
Working with databases
« on: July 03, 2008, 12:11:59 PM »
Hi again,

I browsed and searched this forum for a couple of hours and I can't find anything about working with data(bases). How do I connect to a database e.g. MS SQL, Or any other database? Can I use SQL statements directly in code?

Regards,
Drago

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Working with databases
« Reply #1 on: July 03, 2008, 06:50:05 PM »
Connecting to a database usually depends on the database. ODBC (see http://en.wikipedia.org/wiki/Open_Database_Connectivity) is/was one attempt at supporting multiple databases through a common interface - I'm not sure how much it's used today. The SQL statements are most likely passed as strings to some API function that the database provides. I use SQLite in Pelles C, which is small and easy database engine to start with (see http://www.sqlite.org/). It works fine, unless you want to handle *huge* volumes of data...
/Pelle

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Working with databases
« Reply #2 on: July 03, 2008, 07:57:43 PM »
If you are interest about ODBC look at:
http://forum.pellesc.de/index.php?topic=2489.msg9458#new
May the source be with you

Zodra1

  • Guest
Re: Working with databases
« Reply #3 on: July 04, 2008, 10:03:18 PM »
Thank both for the answers. I would prefer something like MSDE. If possible

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Working with databases
« Reply #4 on: July 05, 2008, 01:10:50 PM »
You can connect to SQL Server or MSDE via ODBC, OLE DB, or DB-Library.
What you prefer to use except ODBC ?

DB-Library example code just for keywords to google.
Code: [Select]
// MSSQL database
PDBPROCESS dbproc; // The connection with SQL Server.
PLOGINREC login; // The login information.

int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR,
LPCSTR, DBUSMALLINT);
dberrhandle(err_handler);
dbmsghandle (msg_handler);
login = dblogin();
dbsetlname(login, 0, DBSETSECURE);
dbproc = dbopen(login, "local");
dbuse(dbproc, "test");
dbexit();


May the source be with you

Zodra1

  • Guest
Re: Working with databases
« Reply #5 on: July 07, 2008, 03:22:08 PM »
Connection to a set of SQL tables is exactly what i was looking for. Many thanks i will test this code as soon as i return from vacation. Thank you again.

Zodra1

  • Guest
Re: Working with databases
« Reply #6 on: July 07, 2008, 03:42:58 PM »
Well it looked simple :). But it isn't quite so. I found functions to be a part of MS SQL library. I know I must do something to access those SQL functions from Pelles but I don't know what. Will keep trying; help is of course welcome and needed  ???.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Working with databases
« Reply #7 on: July 07, 2008, 09:13:45 PM »
If you use ODBC all nessessary files you get with Pelles C.
Why you don't want to start with that ?
When you learn to use that, you can use same code with several databases as i showed in that Tiny Lousy ODBC Hell.
Using DSN-less ODBC you don't have create datasource/change system settings
 because SQL Server connection files/dlls comes with MDAC/MSOffice.

http://www.easysoft.com/developer/languages/c/odbc_tutorial.html


May the source be with you

Zodra1

  • Guest
Re: Working with databases
« Reply #8 on: July 08, 2008, 04:44:48 PM »
Yes, you are right of course. In every aspect. Flexibility and independence is worth a lot. I will try to learn how to use ODBC.