10-15-2011, 06:22 PM
Dose any 1 a idea how i can convter a csv table to a sql file ?
|
Csv to sql
|
|
10-15-2011, 06:22 PM
Dose any 1 a idea how i can convter a csv table to a sql file ?
10-15-2011, 07:00 PM
Ty but the convert only the first 50 :/
10-15-2011, 07:43 PM
Google it there will be tools, guides.
10-16-2011, 10:23 AM
Ive used semicolumns in this example: ifstream in("file.csv", ios::in); ofstream out("file.sql",ios::out); char str[1024]; if(in.is_open()){ //first line which is the table coulumns in.getline(str,1024); pch = strtok (str,";"); while (pch != NULL){ stream2.append(pch); pch = strtok (NULL, ";"); if(pch != NULL){ stream2.append(","); } } while(in.good(){ //getting the data in.getline(str,1024); stream.append("INSERT INTO t_table("); stream.append(stream2.c_str()); stream.append(") VALUES("); pch = strtok (str,";"); while (pch != NULL){ stream.append(pch); pch = strtok (NULL, ";"); if(pch != NULL){ stream.append(","); } } stream.append(");\n"); out << stream; } in.close(); out.close(); } With comma its much easier: ifstream in("file.csv", ios::in); ofstream out("file.sql",ios::out); char str[1024]; if(in.is_open()){ //first line which is the table columns in.getline(str,1024); stream2.assign(line); while(in.good(){ //getting the data in.getline(str,1024); stream.append("INSERT INTO t_table("); stream.append(stream2.c_str()); stream.append(") VALUES("); pch = strtok (str,";"); while (pch != NULL){ stream.append(pch); pch = strtok (NULL, ";"); if(pch != NULL){ stream.append(","); } } stream.append(");\n"); out << stream; } in.close(); out.close(); }
10-16-2011, 10:31 AM
o.O i dont understand this ;//
10-16-2011, 10:36 AM
o.O i dont understand this ;// It reads the file line by line, on CSV usually first line is the columns line, and the rest are the data rows. The code above is C++ code that reads a CSV file and writes an SQL file. You can still try this: 2
10-16-2011, 10:40 AM
;( oh have no knowlege in c# or c++ :/ i try goggle but they a no working tools or TuT ;/
10-16-2011, 11:25 AM
i try goggle but they a no working tools or TuT ;/
|
|
« Next Oldest | Next Newest »
|