codeman
3rd June 2009, 15:42
Hello I have a simple question .
what is the best way to insert content to a database. What about cutting up the string if the content is to long for field in the database. Is there a flag to set for automatic cutting cause when it is to long te insert fails.
Any idea??
This is my approach:
if(qstr_textLine.count(";",Qt::CaseInsensitive)== 2){
qstr_textLine.replace(QString(","), QString("."));
qstr_textLine.replace(QString(";"), QString(","));
qstr_textLine.replace(QString("'"), QString("''"));
QSqlQuery insertquery;
qstr_textLine.replace(QString(","), QString("','"));
qstr_textLine.prepend("'");
qstr_textLine.append("'");
qstr_textLine.replace(QString("'NULL'"), QString("NULL"));
int sqlbool=insertquery.exec("INSERT INTO testtbl (field1,field2,field3) "
"VALUES ("+qstr_textLine+")");
}
I use mssql.
what is the best way to insert content to a database. What about cutting up the string if the content is to long for field in the database. Is there a flag to set for automatic cutting cause when it is to long te insert fails.
Any idea??
This is my approach:
if(qstr_textLine.count(";",Qt::CaseInsensitive)== 2){
qstr_textLine.replace(QString(","), QString("."));
qstr_textLine.replace(QString(";"), QString(","));
qstr_textLine.replace(QString("'"), QString("''"));
QSqlQuery insertquery;
qstr_textLine.replace(QString(","), QString("','"));
qstr_textLine.prepend("'");
qstr_textLine.append("'");
qstr_textLine.replace(QString("'NULL'"), QString("NULL"));
int sqlbool=insertquery.exec("INSERT INTO testtbl (field1,field2,field3) "
"VALUES ("+qstr_textLine+")");
}
I use mssql.