Csv to sql
#1
Dose any 1 a idea how i can convter a csv table to a sql file ?

#2
2
#3
Ty but the convert only the first 50 :/

#4
Google it there will be tools, guides.

#5

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();
}

#6

o.O

 

i dont understand this ;//

#7

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

#8

;( oh

have no knowlege in c# or c++ :/

 

 

i try goggle but they a no working tools or TuT ;/

#9
i try goggle but they a no working tools or TuT ;/



Forum Jump:


Users browsing this thread: 1 Guest(s)