Results 1 to 7 of 7

Thread: QSqlField discovery auto_increment int value

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlField discovery auto_increment int value

    i suppose to find Index field auto_increment from a mysql or other .... fld.isAutoValue() must return true....

    fld.requiredStatus give true ....

    wy is evry QSqlRecord false?

    how i can find it....?


    Qt Code:
    1. QString Browser::StructureTable( QSqlRecord now )
    2. {
    3. QSqlRecord rec = now;
    4. QString createtable;
    5. QString sqltipename;
    6. QStringList CreateTable;
    7. int totalcools = rec.count();
    8. if (totalcools > 0) {
    9. /* sqlite3 table construct from odbc converter */
    10. for (int i = 0; i < totalcools; ++i) {
    11. QSqlField fld = rec.field(i);
    12. QString name = Strtrimmed(fld.name());
    13. QString typeoffield = QString(QVariant::typeToName(fld.type()));
    14. /* fld.isAutoValue() never true from auto_increment mysql ??? */
    15. if (fld.requiredStatus() and i < 2 and typeoffield == "int") {
    16. sqltipename = QString("%1 INTEGER PRIMARY KEY").arg(name);
    17. } else if ( typeoffield == "double" or typeoffield == "int" ) {
    18. sqltipename = QString("%1 NUMERIC").arg(name);
    19. } else if ( typeoffield == "QByteArray") {
    20. sqltipename = QString("%1 BLOB").arg(name);
    21. } else {
    22. sqltipename = QString("%1 TEXT").arg(name);
    23. }
    24. CreateTable.append(sqltipename);
    25. ////////qDebug() << "### fieldname " << name;
    26. ///////////qDebug() << "### typeoffield " << typeoffield;
    27. }
    28. QString midlecreate = CreateTable.join(",");
    29. midlecreate.prepend(QString("CREATE TABLE %1 (").arg(runningtable));
    30. midlecreate.append(");");
    31. createtable = midlecreate;
    32. }
    33. return createtable;
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlField discovery auto_increment int value

    How do you create the QSqlRecord object?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlField discovery auto_increment int value

    Quote Originally Posted by wysota View Post
    How do you create the QSqlRecord object?
    simply on a qtextedit a select statment

    qx is the full query

    QSqlQuery query(qx,connectionWidget->currentDatabase());
    QSqlRecord rec = query.record();


    ////////cvslines.append(StructureMYSQLTable(rec));
    cvslines.append(StructureTable(rec));



    Qt Code:
    1. svn co https://svn.sourceforge.net/svnroot/qtexcel-xslt/_odbc_wizard/ odbcwizard
    2. cd odbcwizard && qmake a.pro && make
    To copy to clipboard, switch view to plain text mode 




    enter the text query && export .....

    Qt Code:
    1. void Browser::exec()
    2. {
    3. last_query = sqlEdit->toPlainText();
    4. tablelisten.clear();
    5. QSqlDatabase currendb(connectionWidget->currentDatabase());
    6. tablelisten = currendb.tables();
    7. for (int i = 0; i < tablelisten.size(); ++i) {
    8. QString tabi = tablelisten.at(i);
    9. if (last_query.contains(tabi,Qt::CaseInsensitive)) {
    10. runningtable = tabi;
    11. }
    12. }
    13. QSqlQueryModel *model = new QSqlQueryModel(table);
    14. model->setQuery(QSqlQuery(last_query,currendb));
    15. table->setModel(model);
    16. if (model->lastError().type() != QSqlError::NoError) {
    17. emit statusMessage(model->lastError().text());
    18. } else if (model->query().isSelect()) {
    19. emit statusMessage(tr("Query OK on table %1").arg(runningtable));
    20. emit registerQuerySuccess(last_query,runningtable); /* take last register table name .... */
    21. } else {
    22. emit statusMessage(tr("Query OK, number of affected rows: %1").arg(
    23. model->query().numRowsAffected()));
    24. }
    25.  
    26. updateActions();
    27. }
    28.  
    29.  
    30. void Export_Xml( QString qx , QString table )
    31. {
    32. bool okformat;
    33. if (table.size() > 0) {
    34. runningtable = table;
    35. }
    36. QStringList items;
    37. items << "XML" << "CSV" << "SQLITE3" << "MYSQL";
    38. QString msgDB =tr("You like to export last \"Query\" from table \"%1\"?").arg(runningtable);
    39. int removeyes = QMessageBox::question(this, tr("Please Confirm:"),msgDB,tr("&Yes"), tr("&No"),QString(),8888,9999);
    40. QString responder = QString::number(removeyes);
    41. if (responder =="0") {
    42. QString form = QInputDialog::getItem(this, tr("Select one export format..."),tr("Format:"), items, 0, false, &okformat);
    43. if (okformat && !form.isEmpty()) {
    44. if (form == "XML") {
    45. ExportXmlPrimary(qx);
    46. } else if (form == "CSV") {
    47. ExportCSVPrimary(qx);
    48. } else if (form == "MYSQL") {
    49. ExportMysql(qx);
    50. } else if (form == "SQLITE3") {
    51. ExportSqlite3(qx);
    52. }
    53. }
    54. }
    55.  
    56. QApplication::restoreOverrideCursor();
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 1st December 2006 at 07:50.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlField discovery auto_increment int value

    How is the code you posted above related to the problem?

    Did you check that the query is valid using QSqlQuery::isValid()?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlField discovery auto_increment int value

    Quote Originally Posted by wysota View Post
    How is the code you posted above related to the problem?

    Did you check that the query is valid using QSqlQuery::isValid()?

    QSqlQuery::isValid() is valid true
    QSqlRecord::requiredStatus() is true
    only QSqlRecord::isAutoValue() is every time false on all field auto_increment mysql or index from sqlite.... http://doc.trolltech.com/4.2/demos-s...owser-cpp.html

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlField discovery auto_increment int value

    What happens if you pass NULL as a value to that field? Does the database generate a correct record for it? I think isAutoValue() will return true only if you first use QSqlField::setAutoValue().

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlField discovery auto_increment int value

    Quote Originally Posted by wysota View Post
    What happens if you pass NULL as a value to that field? Does the database generate a correct record for it? I think isAutoValue() will return true only if you first use QSqlField::setAutoValue().
    i need only to discover a clean shema from odbc driver mysql , access , sqlite ... ecc

    if table is so.....

    Qt Code:
    1. CREATE TABLE `BASE_0` (
    2. `ID` int(22) NOT NULL auto_increment,
    3. `LANGUAGE` varchar(100) default NULL,
    4. `PREFIX` varchar(55) default NULL,
    5. `TITLE` varchar(150) default NULL,
    6. `NAME` varchar(100) default NULL,
    7. `FIRST_NAME` varchar(110) default NULL,
    8. PRIMARY KEY (`ID`)
    9. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    To copy to clipboard, switch view to plain text mode 

    i like to discover field "ID auto_increment" but i think is impossibel to make a clean dump from table .... driver mysql give a different result shema as odbc...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.