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.



  • 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.



  • @Absolute Gravy said:

    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 said:

    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 said:

    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.



  • 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?



  • 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.


  • Sorry about that, I'm coding under Windows (7) using VS2010. I'm also using the Windows API.



  • @Absolute Gravy said:

    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.



  • @blakeyrat said:

    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.



  • @ekolis said:

    @blakeyrat said:
    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.



  • @ekolis said:

    @blakeyrat said:
    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".



  • The registration links are broken, and it seems from the license that it is no longer required.



  • 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!?



  • @Absolute Gravy said:

    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?



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

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


  • Discourse touched me in a no-no place

    @Absolute Gravy said:

    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 />


  • @Absolute Gravy said:

    my browser is Google Chrome.
     

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

    I'm sorry.



  • @dhromed said:

    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.



  • 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).



  • 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.


  • @Absolute Gravy said:

    * 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.



  • @Absolute Gravy said:

    * 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?


  • ♿ (Parody)

    @lettucemode said:

    @Absolute Gravy said:
    * 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?



  • @boomzilla said:

    @lettucemode said:
    @Absolute Gravy said:
    * 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 said:

    Or copy-paste SQLite (public domain) into your program and compile it.

    Not adequate for you?


  • ♿ (Parody)

    @lettucemode said:

    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.



  • Yea...I tend to post in a stream-of-consciousness sort of way.



  • .. and not proof-read before hitting POST.

    It happens to the best of us....



  • Do not go recreating wheel, if wheel already exist. (Second law of computer programming).



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



  • @Cassidy said:

     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.



  • @Nagesh said:

    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 said:

    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 said:

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

    They seek him here, they seek him there.



  • 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. :)



  • 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.

     


Log in to reply