-
DataBase access
howdy,
i am at the point in an app where i will be accessing a database (AISC steel section properties). will i need a seperate utilitie to open a database and access it by field name etc...
or does C++ have a library function that will allow searching a database by row or column.
i have no code to offer because i have no idea how this is even attempted.
~~~~~~~wannabe code~~~~~~~~~~
int i_have _a_value()
{
look in the data base for 5 values
1 = i_have _a_value
2 = next_two_higher_values
2 = next_two_lower_values
retrieve the entire rows containing these values
} // or something like this
~~~~~~wannabe code~~~~~~~~~~~~~~
the data base will be several hundred rows and about 20 columns.
where do i start?
Thanks
M.R.:(
-
Ask your database vendor if he provides you with an interface to C/C++. It very likely he will. It's a set of functions that you can use to access the data stored in the database. I can't tell you more, as the actual implementation is database specific. For Oracle for example, it's the OCI, Oracle Call Interface. For other vendors, there might be other solutions.
-
Are you using a professional/commercal database? If so nvoigt already answered your point.
Or do you want to create a simple database yourself?
You could make a structure or class to hold all the data for each object.
Then make an array or whatever you want with this class.
Using FILE * 's you can read and write entier arrays at once
Code:
FILE * myfile;
int array[500];
int array2[500];
int i;
for( i=0 ; i<500 ; i++)
{
array[i]=i;
}
myfile = fopen("database","wb");//write/binary
fwrite(array,sizeof(int),500,myfile); //this should write the whole array to the text file
fclose(myfile); //close the file.
//do stuff here
myfile = fopen("database","rb"); //open the file for reading
fread(array2,sizeof(int),500,myfile); //read in our array we wrote earlier
That will make an array, write it to a file.
Then the file is closed.
The file can then be opened, and read in with one line