The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

C++, databases and SQL, can anyone help?

Last post 08-03-2012 4:17 AM by Cbuttius. 31 replies.
Page 1 of 1 (32 items)
Sort Posts: Previous Next
  • 04-21-2012 8:52 PM

    C++, databases and SQL, can anyone help?

    Greetings. I feel I know a reasonable amount of C++, and for what I'm working for part of my University project I have decided I need a database because I'll be storing a lot of data. However, although we did a short module on databases a couple of years ago, I had nothing to apply what they were talking to us about to, and ultimately I've forgotten pretty much everything they spoke about. They did not get lectured on SQL. Anyway, I am aware that 'SQL queries' are used to add and retrieve data from a database of some kind. How this is done I do not know, I would assume there is some sort of interface depending on the type of database. So, the basic outline of what I want to do is (using C++) create a database that I can access using SQL queries. I have done some research and various acronyms were hurled at me along with various names; ODBC, DTL, ADO, SQLite... I repeatedly get results referring to 'SQL Server'. Now maybe I do not understand the term, but I'm trying to create and utilise a local database here, not something that runs on a server. Does anyone have any experience with any of this? EVEN if you do not know any C++, if you have experience working with databases and/or any of the systems I have mentioned above, or anything else for that matter, please reply with whatever information you may know that you feel may be of use to me, if you can. Or reply requesting further details on what I'm trying to do. Thanks in advance. EDIT: I apologise for the apparent lack of paragraphs in my post. For some reason when posting, it appears to ignore them.
  • 04-22-2012 3:49 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Your question's pretty vague. Relational Databases are an entire field of computer science, it would take days just to explain, for example, normalization. You'd probably be best off getting a book. When I was in school, I relied on Database Systems: A Practical Approach to Design, Implementation, and Management. That was a decade, and two editions, ago-- but databases haven't really changed much.

    Why C++? Last time I checked the calendar it was 2012.

      <-  I couldn't make my shit work, so here's a Godzilla head.
  • 04-22-2012 4:07 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:

    Anyway, I am aware that 'SQL queries' are used to add and retrieve data from a database of some kind. How this is done I do not know, I would assume there is some sort of interface depending on the type of database.

    SQL is "Standard Query Language" (or Structured Query Language), used for not only querying databases but for manipulating data within, as well as other things. You're correct in that it is used for database operations.

    Yes, some kind of interfaces exist - some nothing more than a command shell for SQL statements, others graphical. Some are provided for other languages to connect and send SQL statements to the DB (such as ODBC and the like)

     

    Absolute Gravy:

    So, the basic outline of what I want to do is (using C++) create a database that I can access using SQL queries.

    I'm guessing you meant "I want to access a DB using SQL queries through C++" - your sentence there sounds like you want to actually write a database in C++.

    Absolute Gravy:

    Now maybe I do not understand the term, but I'm trying to create and utilise a local database here, not something that runs on a server. Does anyone have any experience with any of this?

    Yes. MySQL and SQLite are two free databases available to download and install. However, it sounds like you need to pick up a smattering of SQL to understand what statements you want to throw at the database before looking at popping those into some C++ code (and to provide expected results to compare).

    In short, what you're asking for isn't impossible. It does sound like you need to find another module in databases or do more research to give you a better grounding in database, else you'll flounder badly when it comes to data manipulation.

  • 04-22-2012 4:52 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    I do indeed want to create the database if the database file does not exist. Is this possible without requiring the user being required to install other software?
  • 04-22-2012 5:13 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Okay, we're getting into new territory now. You've essentially got two options:

    1. use an off-the-shelf RDBMS (as mentioned above) and write code that connects and throws SQL at it
    2. use some lower-end binary DB format that your code can access, like DBM hashes, or even CSV/TSV/Access MDBs/Excel spreadsheets.
    The latter could be what you want, but you won't need SQL to access it. BTW: you've given no indication of platforms (OS), which may help.
  • 04-22-2012 5:32 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Sorry about that, I'm coding under Windows (7) using VS2010. I'm also using the Windows API.
  • 04-22-2012 10:24 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:
    Sorry about that, I'm coding under Windows (7) using VS2010. I'm also using the Windows API.
    I believe SQL Server Express edition (database size up to 10 GB) can be redistributed-- don't take my word for it, check the docs. SQL Server is by far the best DB server you'll find for free.

    Other than that, MySQL is open source, so you can redist it. It's also popular, so you should be able to find lots of help out there for it.

    SQLite can actually be compiled into your program, but it chokes at relatively small DB sizes.

      <-  I couldn't make my shit work, so here's a Godzilla head.
  • 04-22-2012 5:59 PM In reply to

    • ekolis
    • Top 100 Contributor
    • Joined on 01-09-2008
    • Cincinnati, OH, USA
    • Posts 600

    Re: C++, databases and SQL, can anyone help?

    blakeyrat:
    I believe SQL Server Express edition (database size up to 10 GB) can be redistributed-- don't take my word for it, check the docs. SQL Server is by far the best DB server you'll find for free.
    You're probably thinking of SQL Server Compact Edition - though Express is free as well, just not redistributable.
    I'm Spark Mandrill, and I'll... hey... can I... what, it BOUNCES?... 'kay, I'm splodin' now.
  • 04-22-2012 7:51 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    ekolis:
    blakeyrat:
    I believe SQL Server Express edition (database size up to 10 GB) can be redistributed-- don't take my word for it, check the docs. SQL Server is by far the best DB server you'll find for free.
    You're probably thinking of SQL Server Compact Edition - though Express is free as well, just not redistributable.
    No. I was thinking Express. I just didn't know if Express was redistributable or not. As I started in the freakin' post.

    If I meant Compact, I would have typed Compact. I didn't, because Compact has only a 4 GB limit which, IMO, is simply not large enough for most database-requiring applications.

      <-  I couldn't make my shit work, so here's a Godzilla head.
  • 04-22-2012 7:56 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    ekolis:
    blakeyrat:
    I believe SQL Server Express edition (database size up to 10 GB) can be redistributed-- don't take my word for it, check the docs. SQL Server is by far the best DB server you'll find for free.
    You're probably thinking of SQL Server Compact Edition - though Express is free as well, just not redistributable.
    You can redistribute SQL Express, but you have to register for redistribution rights. SQL 2012 also has an in-process version called "LocalDB".
  • 04-22-2012 8:00 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    The registration links are broken, and it seems from the license that it is no longer required.
  • 04-23-2012 7:37 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    I'd prefer not to have to distribute any additional prerequisite programs for my program to be usable on another machine. I'd much rather have whatever the solution is compiled in to my program and be standalone. EDIT: Also, this may be an incredibly dumb question, but how on Earth do I actually put new lines in to my posts!? When I go to edit my post like now, I can SEE the new lines, but when I post...it ignores them. This Edit for example should be on a new line. Am I missing something!?
  • 04-23-2012 7:40 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:
    EDIT: Also, this may be an incredibly dumb question, but how on Earth do I actually put new lines in to my posts!? When I go to edit my post like now, I can SEE the new lines, but when I post...it ignores them. This Edit for example should be on a new line. Am I missing something!?

    I'm using the TinyMCE editor

    ..

    .. which allows newlines

    ...   in the 

     

    middle of text. How do you do it?

  • 04-23-2012 7:41 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    I hit reply or quick-reply on this website and type in the Message Box that appears.&nbsp If it matters, my browser is Google Chrome.

    EDIT: It would seem I need to use html paragraph tags...

  • 04-23-2012 8:13 AM In reply to

    • PJH
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Newcastle, UK
    • Posts 3,919

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:

    I hit reply or quick-reply on this website and type in the Message Box that appears.&nbsp If it matters, my browser is Google Chrome.

    EDIT: It would seem I need to use html paragraph tags...

    Or use <br />
    "Because you watched 'The Very Hungry Caterpillar,' we recommend 'The Human Centipede.'"
    --
    UED - Countryside: To kill Piers Morgan
  • Parp!
  • 04-23-2012 8:31 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:
    my browser is Google Chrome.
     

    This website hates Chrome. It is old and wants Chrome to get off its lawn.

    I'm sorry.


    In complex analysis, a meromorphic function on an open subset D of the complex plane is a function that is holomorphic on all D except a set of isolated points

  • 04-23-2012 9:20 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    dhromed:
    This website uses an older version of TinyMCE that hates Chrome.

    FTFY - the issue lies not in the site but in the management thereof, AIUI.

  • 04-23-2012 10:23 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Alright then, that aside, does anyone have any advice?

    I'll re-iterate what I'm doing and what I need:

    * I'm coding in C++

    * I'm coding under Windows and using the Windows API

    * I want to create a LOCAL database of some kind if it does not exist for the program to access

    * I want the program to be able access, read and write to said database

    * I want the program to be able to do the above things without the installation of other programs being required (bar the machine running the Windows OS).

  • 04-23-2012 10:58 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    SQLite sounds like the most obvious choice that meets your requirements.

    SQL Server Express is a lot more more, but will give you a more powerful database engine.
  • 04-23-2012 11:47 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:
    * I want to create a LOCAL database of some kind if it does not exist for the program to access

    Then read/write out to a plain-text file of some kind (unless C++ supports some native binary DB format).

    All the RDBMS to use are going to require installing some additional product. If you want to do it without, you need to look at what DB files C++ can use natively.

  • 04-24-2012 10:15 AM In reply to

    • lettucemode
    • Top 500 Contributor
    • Joined on 12-15-2011
    • Location: confirmed, sending supplies.
    • Posts 223

    Re: C++, databases and SQL, can anyone help?

    Absolute Gravy:

    * I want the program to be able to do the above things without the installation of other programs being required (bar the machine running the Windows OS).

    You'll be writing your own database software then. Do like Blakeyrat suggested and get a book; databases are complex, but solved. Though you really should save yourself months of work and just install an already existing, tried-and-true database (SQLite, MySQL, SQL Server Express). Or copy-paste SQLite (public domain) into your program and compile it.

    Then again, doesn't some version of SQL Server come stock with Windows 7 nowadays?

    May your forehead grow like the mighty oak.
  • 04-24-2012 10:28 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    lettucemode:
    Absolute Gravy:
    * I want the program to be able to do the above things without the installation of other programs being required (bar the machine running the Windows OS).
    You'll be writing your own database software then.
    No, he doesn't?
    I denounce myself for this post
  • 04-24-2012 10:34 AM In reply to

    • lettucemode
    • Top 500 Contributor
    • Joined on 12-15-2011
    • Location: confirmed, sending supplies.
    • Posts 223

    Re: C++, databases and SQL, can anyone help?

    boomzilla:
    lettucemode:
    Absolute Gravy:
    * I want the program to be able to do the above things without the installation of other programs being required (bar the machine running the Windows OS).
    You'll be writing your own database software then.
    No, he doesn't?
    You missed this part:
    lettucemode:
    Or copy-paste SQLite (public domain) into your program and compile it.

    Not adequate for you?
    May your forehead grow like the mighty oak.
  • 04-24-2012 10:56 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    lettucemode:
    Not adequate for you?
    Meh....I didn't pay attention enough to notice that you later contradicted your opening (and admittedly incorrect) sentence. An odd attempt at communication.
    I denounce myself for this post
  • 04-24-2012 11:12 AM In reply to

    • lettucemode
    • Top 500 Contributor
    • Joined on 12-15-2011
    • Location: confirmed, sending supplies.
    • Posts 223

    Re: C++, databases and SQL, can anyone help?

    Yea...I tend to post in a stream-of-consciousness sort of way.
    May your forehead grow like the mighty oak.
  • 04-24-2012 1:56 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    .. and not proof-read before hitting POST.

    It happens to the best of us....

  • 05-02-2012 10:48 AM In reply to

    • Nagesh
    • Top 50 Contributor
    • Joined on 01-31-2011
    • Hyderabad, India
    • Posts 1,070

    Re: C++, databases and SQL, can anyone help?

    Do not go recreating wheel, if wheel already exist. (Second law of computer programming).
  • 05-02-2012 11:51 AM In reply to

    Re: C++, databases and SQL, can anyone help?

     So.. if a wheel exists but is in use elsewhere, it's okay to steal it rather than recreate another?

  • 05-03-2012 2:23 PM In reply to

    • Nagesh
    • Top 50 Contributor
    • Joined on 01-31-2011
    • Hyderabad, India
    • Posts 1,070

    Re: C++, databases and SQL, can anyone help?

    Cassidy:

     So.. if a wheel exists but is in use elsewhere, it's okay to steal it rather than recreate another?

    Beauty of profession is no need to steal. Once wheel creation is complete, it is available for everybody at same time. In real world, if design for wheel is in existence, then you make copy of design and use it.

    If you are confusing by my statement, seek clarification and I will provide it.

  • 05-03-2012 7:39 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    Nagesh:
    Beauty of profession is no need to steal. Once wheel creation is complete, it is available for everybody at same time.

    So... there's one wheel and everyone uses it on a rota basis? That's sharing gone mad!

    Nagesh:
    In real world, if design for wheel is in existence, then you make copy of design and use it.

    ... and people wonder where these rip-off counterfeits originate from. I rest my case.

    Nagesh:
    If you are confusing by my statement, seek clarification and I will provide it.

    They seek him here, they seek him there.

  • 05-05-2012 8:01 PM In reply to

    Re: C++, databases and SQL, can anyone help?

    Is he in Heaven or is he in Hell? That damned elusive...Pimpernel!?


    More seriously, due to time constraints I've managed to learn how to write instances of my classes to files. It's probably not as efficient as some of these other systems, but it will do. Thanks for your input people. :)

  • 08-03-2012 4:17 AM In reply to

    Re: C++, databases and SQL, can anyone help?

    If you want to code in C++ and you are allowed to get open-source then get the SOCI library which works with multiple databases.

    ODBC is a standard supported on Windows but is C-only. You can call it from C++ but have to do lots of management as is the case when using C. SOCI will do a lot of that management for you.

     

Page 1 of 1 (32 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems