I'm trying to load dxf files CAD into a database for searching.
Some of these files are huge with hundreds of thousand of separate entites.
I've separated the file into the following tables:
- drawings
- layers
- style
- entities
- points
- flags
- floats
- text
The drawing table contains a path to the drawing and an ID for each drawing.
The layers has an ID, the Drawing ID, a text name, a colour and a linetype.
The style has an ID, the Drawing ID, a text name.
The enities table has an ID, the Drawing ID, an etity type, layer, style and a location (point).
The points table has the idetity ID to which it belongs and 3 floats indicating x, y and z coordinates
Some enities use flags to further define the entity; a bit may be set to indicate a closed polyline, for example. The flags table contains the ID reference to the entity, the flag type and the flag integer itself.
Simialary, an entity may have additional floats (radius for a circle), or text.
I am writing a cpp program to parse the drawing file and insert the info into a database.
Currently I'm using MySQL:
struct connection_details
{
string server;
string user;
string password;
string database;
};
void initDXFDB(struct connection_details mysql_details){
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,mysql_details.server.c_str(),
mysql_details.user.c_str(),
mysql_details.password.c_str(),
mysql_details.database.c_str(),0,NULL,0)){
printf("Failed to connect to database: Error: %s\n", mysql_error(&mysql));
}
}
void load_new_file(string DB, string name, string path){
struct connection_details mysqlD;
mysqlD.server = "localhost"; // where the mysql database is
mysqlD.user = "root"; // the root user of mysql
mysqlD.password = "********"; // the password of the root user in mysql
mysqlD.database = DB; // the databse to pick
initDXFDB(mysqlD);
drawing_ID=insertRecords("drawing","name,path","'"+name+"','"+path+"'");
insertTecords("entities",...,...);
...
...
mysql_close(&mysql);
}
Firstly, would I be better off using a SQLite database? The database will need to be interrogated over the Web, which is why I'm using MySQL at the moment.
Secondly, my test file (which is admitedly 50meg) is taking a few hours to process and presumably there is a more ifficient way of inserting thousands of records other than sequentially.