Results 1 to 11 of 11

Thread: Any suggestions on a good database to use with C++ inventory-control program?

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Talking Any suggestions on a good database to use with C++ inventory-control program?

    Hello everyone,

    With the help of CornedBee I figured out what I want to do for my term project but I'm curious if anyone has any experience with working with C++ and databases. I'm going to be creating an Inventory-Control program that will do the following:

    -Allow the user to input part quantity, price per unit, part name
    -track the cost of parts and where in the warehouse they are located
    -alert the parts manager when the on-hand inventory falls below the target level, so parts can be re-ordered.
    -sort by part name/part number/quantity

    Also if I need more lines of code to hit 1,000 i will implement
    -calculate inventory costs on a Last-in-first-out basis AND on a First-in-first-out basis.

    But I'm wondering what the best database to handle all of this information and to store it. Are there any C++ libraries out there that are specially made for database management and accessing databases?

    If I need at least 1,000 lines of code, would I just store all the information in a text file, that to me seems like a bad solution but I've never written such a program so I'm not sure what would be a good idea or bad idea.

    Thanks!
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    Lots and lots of libraries. Just about every database has a native C API, which of course can be used from C++. Then there's the adapter libraries, like MySQL++, SOCI, sqlpp and many more.

    Whether you actually use a database or you just do in-memory stores with read and write of a text file depends mostly on the data volume. Note also that using an SQL library, some stuff can become embarassingly short.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    Thanks again,

    I e-mailed the professor about it as well, so i'll probably go to text file route to make sure it isn't simplified too much.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  4. #4

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    I'm wondering if mySQL++ is a good idea or not, alot of people are having issues with it as am I.

    I was reading you could connect to a mySQL database with ODBC, but then i'm not sure how to go about writing mySQL statements to access tables, create tables, etc in the mySQL database.

    I wasn't able to find any good tutorials on this, perhaps i'm not googling for the right thing.

    Should I be googling for ODBC C++ C API mySQL tutorials?
    or what would I use to "talk" to the database?


    thanks sorry i'm very confused any tutorial would be great!
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    SQL is a standard. While different DBs have slight dialects (especially in the area of quoting: MySQL uses `name` to quote field names, Postgres and Oracle "name", MSSQL [name], ...), the core is the same everywhere.

    So if you know SQL in principle, it's really just a matter of browsing the reference of the DB and checking how to execute SQL with your library of choice.

    By the way, I heard that ODBC isn't exactly easy to set up. Certainly it won't allow you to easily move your program from one computer to another and just execute it there. If you want that capability, I really recommend SQLite.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    i really wouldn't bother with mysql++

    go to mysql.org, grab the full installer. when installing, be sure to check that you want the source installed too. also grab the admin gui tools.

    setup your ide/project so that it's aware of mysql path\include (add as an include dir) and mysql path\lib\debug [debug] or mysql path\lib\opt [release] (add as a library dir)

    then #include <mysql.h> and possibly winsock

    edit:
    here is something to get the ball rolling

    Code:
    MYSQL* mysqlConnection = mysql_init(NULL);
    
    if (!mysql_real_connect(mysqlConnection, "localhost", "root", "password", "db", 3306, NULL, 0))
    	//error, use mysql_error(mysqlConnection)
    else
    {
    	if (mysql_query(mysqlConnection,"SELECT * FROM blah") != 0)
    		//error, use mysql_error(mysqlConnection)
    	else
    	{	
    		MYSQL_RES* result = mysql_store_result(mysqlConnection);
    
    		MYSQL_ROW row;
    		// get the rows 1 by 1
    		while ((row = mysql_fetch_row(result)))
    		{
    			// do stuff
    			// row[0] is the contents of col1 of the current row
    			// row[1] is the contents of col2 etc
    		}
    		
    		mysql_free_result(result);
    	}
    
    	mysql_close(mysqlConnection);
    }
    more info here and here
    Last edited by dis1411; Jan 21st, 2007 at 07:18 PM.

  7. #7

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    Thanks for the help,
    I get the following problems when trying to connect to a database that is locally on my machine...

    Code:
    #include <mysql.h>
    #include <iostream>
    using namespace std;
    
    
    int main()
    {
    	Database db("localhost", "root", "carNeus2", "tutorialdb");
    	if (!db.Connected())
    	{
    		cout << "Database not connected - exiting\n";
    	}
    }
    The database I created with mySQL 5.0 command line, with the following:
    Code:
    Enter password: ********
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 5.0.27-community-nt
    
    mysql> create database tutorialdb
        -> ;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> use tutorialdb;
    Database changed
    mysql> CREATE TABLE player (
        ->  num integer auto_increment not null,
        ->  name varchar(100) default '' not null,
        ->  primary key(num),
        ->  unique(name)
        -> );
    Query OK, 0 rows affected (0.09 sec)
    
    mysql>
    mysql> CREATE TABLE resource (
        ->  num integer auto_increment not null,
        ->  name varchar(100) default '' not null,
        ->  primary key(num),
        ->  unique(name)
        -> );
    Query OK, 0 rows affected (0.06 sec)
    
    mysql>
    mysql> CREATE TABLE playerresource (
        ->  player integer default 0 not null,
        ->  resource integer default 0 not null,
        ->  amount integer default 0,
        ->  primary key(player, resource)
        -> );
    Query OK, 0 rows affected (0.06 sec)
    
    mysql>

    Here are my errors:
    Code:
    1>------ Build started: Project: sss, Configuration: Debug Win32 ------
    1>Compiling...
    1>test.cpp
    1>c:\mysql\include\mysql_com.h(184) : error C2146: syntax error : missing ';' before identifier 'fd'
    1>c:\mysql\include\mysql_com.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\mysql\include\mysql_com.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\mysql\include\mysql_com.h(354) : error C2065: 'SOCKET' : undeclared identifier
    1>c:\mysql\include\mysql_com.h(354) : error C2146: syntax error : missing ')' before identifier 's'
    1>c:\mysql\include\mysql_com.h(355) : error C2059: syntax error : ')'
    1>.\test.cpp(8) : error C2065: 'Database' : undeclared identifier
    1>.\test.cpp(8) : error C2146: syntax error : missing ';' before identifier 'db'
    1>.\test.cpp(8) : error C3861: 'db': identifier not found
    1>.\test.cpp(9) : error C2228: left of '.Connected' must have class/struct/union
    1>        type is ''unknown-type''
    1>Build log was saved at "file://c:\Documents and Settings\Mr. Coffee\My Documents\Visual Studio 2005\Projects\sss\sss\Debug\BuildLog.htm"
    1>sss - 10 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Any idea? It seems like the compiler errrors are coming from the library supplied by mySQL 5.0 which is odd.


    EDIT: the orignal code was C, not C++ so i made some adjustments
    Last edited by voidflux; Jan 21st, 2007 at 09:06 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  8. #8

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    n/m, that sample code I posted was requiring a wrappersql library I didn't have...
    I used your code:
    Code:
    #include <mysql.h>
    #include <winsock.h>
    #include <iostream>
    using namespace std;
    
    MYSQL* mysqlConnection = mysql_init(NULL);
    
    if (!mysql_real_connect(mysqlConnection, "localhost", "root", "pw", "tutorialdb", 3306, NULL, 0))
    	//error, use mysql_error(mysqlConnection)
    else
    {
    	if (mysql_query(mysqlConnection,"SELECT * FROM blah") != 0)
    		//error, use mysql_error(mysqlConnection)
    	else
    	{	
    		MYSQL_RES* result = mysql_store_result(mysqlConnection);
    
    		MYSQL_ROW row;
    		// get the rows 1 by 1
    		while ((row = mysql_fetch_row(result)))
    		{
    			// do stuff
    			// row[0] is the contents of col1 of the current row
    			// row[1] is the contents of col2 etc
    		}
    		
    		mysql_free_result(result);
    	}
    
    	mysql_close(mysqlConnection);
    }
    Just to see if it will compile but i'm getting more odd errors like the one above, like this:
    Code:
    1>------ Build started: Project: sss, Configuration: Debug Win32 ------
    1>Compiling...
    1>fggf.cpp
    1>c:\mysql\include\mysql_com.h(184) : error C2146: syntax error : missing ';' before identifier 'fd'
    1>c:\mysql\include\mysql_com.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\mysql\include\mysql_com.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\mysql\include\mysql_com.h(354) : error C2065: 'SOCKET' : undeclared identifier
    1>c:\mysql\include\mysql_com.h(354) : error C2146: syntax error : missing ')' before identifier 's'
    1>c:\mysql\include\mysql_com.h(355) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(40) : error C2378: 'SOCKET' : redefinition; symbol cannot be overloaded with a typedef
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(56) : error C2146: syntax error : missing ';' before identifier 'fd_array'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(63) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(744) : error C2143: syntax error : missing ';' before '__stdcall'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(747) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(750) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(750) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(752) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(754) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(754) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(754) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(757) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(757) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(759) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(762) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(762) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(764) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(767) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(767) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(769) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(772) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(772) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(774) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(777) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(777) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(781) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(792) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(792) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(793) : error C2059: syntax error : 8\VC\PlatformSDK\include\winsock.h(806) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(811) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(821) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(821) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(824) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(827) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(827) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(832) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(835) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(835) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(839) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(842) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(842) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(843) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(845) : error C2143: syntax error : missing ';' before '__stdcall'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(845) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(845) : error C2371: 'SOCKET' : redefinition; different basic types
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(848) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(944) : error C2146: syntax error : missing ')' before identifier 's'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(944) : warning C4229: anachronism used : modifiers on data are ignored
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h(947) : error C2059: syntax error : ')'
    1>C:\Program Files\Microsoft Visual Studio C2447: '{' : missing function header (old-style formal list?)
    1>Build log was saved at "file://c:\Documents and Settings\Mr. Coffee\My Documents\Visual Studio 2005\Projects\sss\sss\Debug\BuildLog.htm"
    1>sss - 60 error(s), 19 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    They are all coming from mysql_com.h that is in my mysql 5.0 folder
    Last edited by voidflux; Jan 21st, 2007 at 10:20 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  9. #9
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    include winsock before mysql

  10. #10

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    thanks dis!

    Never thought of that...
    I'll mess around some more and see if I can get something accomplished
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

  11. #11

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Re: Any suggestions on a good database to use with C++ inventory-control program?

    I said screw the SQL database, i'm using a text file and I'm getting alot done. I"ll wait for another project to mess with SQL.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width