Thread: accessing an SQL database through C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    accessing an SQL database through C++

    I'd like to access an SQL database from within a Win32 application using C++. Does anyone have experience or suggestions on doing this?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    I've used C to access MySQL. It was pretty straight forward. I can share my example if you want.

    In my day job, I work with a very large RDBMS, and C++ is one of the languages for which we provide an API - I just haven't gone there yet. All my work has traditionally been accessing the db via Assembler, and I've just gotten into Java as well.

    What RDBMS did you have in mind? Do you have any installed? Windows?
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Im going to use SQL, since I already have access to an SQL database system on my website and thus wont have to set anything up other than create another database ( I already have one but dont want it corrupted).

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think what Dino was trying to say is "which SQL variant are you looking at", as they are very similar but not the same, so you usually have to know if it's MySQL (which there is easy access C code to use - and of course C code can be wrapped in a C++ wrapper if you want), MS Access (which I'm sure MS has access (no pun intended) functions for), or for example Oracle or DB2, which I'm sure the respective companies have interfaces for in C and/or C++.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I use ODBC

    Connect using a DSN to hold site specific DB settings.

    MFC makes this a 2 min job.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Yes, I will unfortunately have to use MFC for this task, but I will probably wrap it in a DLL so I can access it from non-MFC code.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    ODBC is not a database, but merely a protocol (API) for accessing a database. See here: http://en.wikipedia.org/wiki/Odbc

    SQL is the language to tell the relational database system what you want. Different DBMSs support different flavors of SQL.

    Which database will you be using? Or, perhaps you don't know yet because you haven't picked one or don't know what is available.
    Mainframe assembler programmer by trade. C coder when I can.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Dino View Post
    ODBC is not a database, but merely a protocol (API) for accessing a database. .
    Yes ODBC is used to access most types of DBs. Which is what the OP asked for.

    Quote Originally Posted by Dino View Post
    SQL is the language to tell the relational database system what you want. Different DBMSs support different flavors of SQL. .
    The differences in actual SQL between different versions is minor. In most cases it will not matter.

    Quote Originally Posted by Dino View Post
    Which database will you be using? Or, perhaps you don't know yet because you haven't picked one or don't know what is available.
    Or know it is irrelevant to the discussion, based on the design used/application requirements.



    EDIT: I think you are under-estimating our experience.
    Last edited by novacain; 11-20-2008 at 05:51 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    188

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Using database in C++ with SQL. is it posible???
    By Lauris in forum C++ Programming
    Replies: 4
    Last Post: 04-18-2007, 09:31 AM
  3. Parsing a flat file to a SQl Server database?
    By Michael71 in forum C Programming
    Replies: 0
    Last Post: 01-16-2007, 12:45 PM
  4. accessing a database made in Access..
    By willc0de4food in forum Windows Programming
    Replies: 4
    Last Post: 10-10-2005, 07:40 PM
  5. SQL database Interaction
    By (TNT) in forum C++ Programming
    Replies: 1
    Last Post: 07-14-2003, 03:52 AM