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:

Qt Code:
  1. if(qstr_textLine.count(";",Qt::CaseInsensitive)== 2){
  2. qstr_textLine.replace(QString(","), QString("."));
  3. qstr_textLine.replace(QString(";"), QString(","));
  4. qstr_textLine.replace(QString("'"), QString("''"));
  5. QSqlQuery insertquery;
  6. qstr_textLine.replace(QString(","), QString("','"));
  7. qstr_textLine.prepend("'");
  8. qstr_textLine.append("'");
  9. qstr_textLine.replace(QString("'NULL'"), QString("NULL"));
  10.  
  11. int sqlbool=insertquery.exec("INSERT INTO testtbl (field1,field2,field3) "
  12. "VALUES ("+qstr_textLine+")");
  13. }
To copy to clipboard, switch view to plain text mode 

I use mssql.