First of all thx for Your help.

The database is MariaDB 5.5 on opensuse 13.1

I tried Your suggestion ChrisW67 and I converted it to bindValue but it does not help

Qt Code:
  1. query.prepare("INSERT INTO Ruchy (z,do,twr_id,ilosc,opis,czas,dozor_prc_id) VALUES (:z,:do,:twr_id,:ilosc,:opis,now(),:dozor_prc_id)");
  2. query.bindValue(":z",ui->LE_ruchy_z_id->text());
  3. query.bindValue(":do",ui->LE_ruchy_do_id->text());
  4. query.bindValue(":twr_id",ui->LE_ruchy_twr_id->text());
  5. query.bindValue(":ilosc",QString::number(ui->SB_ruchy_ilosc->value()));
  6. query.bindValue(":opis",ui->PTE_ruchy_opis->toPlainText());
  7. query.bindValue(":dozor_prc_id",QString::number(::prc_id));
  8.  
  9. query.exec();
To copy to clipboard, switch view to plain text mode 

the table deffinition is as follows

Qt Code:
  1. CREATE TABLE `Ruchy` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `z` int(11) DEFAULT NULL,
  4. `do` int(11) DEFAULT NULL,
  5. `twr_id` int(11) DEFAULT NULL,
  6. `ilosc` int(11) DEFAULT NULL,
  7. `opis` varchar(450) COLLATE utf8_unicode_ci DEFAULT NULL,
  8. `czas` datetime DEFAULT NULL,
  9. `dozor_prc_id` int(11) DEFAULT NULL,
  10. PRIMARY KEY (`id`)
  11. ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
To copy to clipboard, switch view to plain text mode 


the strange think is that that the LastInsertId() works on other table sreturning the ID but not here

If I export qDebug()<< query.lastQuery() as a text to MYSQL workbench then the row is inserted without any problems - this is strange

I will attache the whole function that contains this insert bellow so You'll be able to track it maybe

Qt Code:
  1. void MainWindow::on_PB_ruchy_zapisz_clicked()
  2. {
  3. if (ui->LE_ruchy_do_id->text().isEmpty() or ui->LE_ruchy_z_id->text().isEmpty() or ui->LE_ruchy_twr_id->text().isEmpty())
  4. {
  5. QMessageBox msgBox;
  6. msgBox.setText("Musisz wybrac magazyn zrodlowy, docelowy, oraz towar");
  7. msgBox.exec();
  8. return;
  9. }
  10.  
  11. QSqlQuery query;
  12.  
  13. query.prepare("LOCK TABLE inicio.Stany WRITE");query.exec();
  14.  
  15.  
  16.  
  17. query.prepare("SELECT id,stan from Stany where twr_id='"+ui->LE_ruchy_twr_id->text()+"' and magazyn_id='"+ui->LE_ruchy_z_id->text()+"'" );
  18. query.exec();
  19. if (query.next())
  20. {
  21. int stan=query.value(1).toInt();
  22. if (stan>=ui->SB_ruchy_ilosc->value())
  23. {
  24. query.prepare("UPDATE Stany set stan=stan-"+QString::number(ui->SB_ruchy_ilosc->value())+" where id='"+query.value(0).toString()+"' ");
  25. query.exec();
  26. }
  27. else
  28. {
  29. if (ui->LE_ruchy_z_id->text()!="-2")
  30. {
  31. QMessageBox msgBox;
  32. msgBox.setText("Nie mozna wydac wiecej niz jest na stanie \n \n Na stanie: "+QString::number(stan)+" szt.");
  33. msgBox.exec();
  34. return;
  35. }
  36. }
  37.  
  38.  
  39. }
  40. else
  41. {
  42. if (ui->LE_ruchy_z_id->text()=="-2")
  43. { //mozna wydac z zerowego stanu tylko przy zakupach - zakupy maja prc_id=-2
  44. query.prepare("INSERT INTO Stany (magazyn_id,twr_id,stan) VALUES ('"+ui->LE_ruchy_z_id->text()+"','"+ui->LE_ruchy_twr_id->text()+"','"+QString::number(0-ui->SB_ruchy_ilosc->value())+"')");
  45. query.exec();
  46. }
  47. else
  48. {//jesli ktos nie ma to nie moze wydac
  49. QMessageBox msgBox;
  50. msgBox.setText("Nie ma tego towaru w magazynie zrodlowym wiec nie moze on go wydac");
  51. msgBox.exec();
  52. return;
  53. }
  54.  
  55. }
  56.  
  57. query.prepare("INSERT INTO Ruchy (z,do,twr_id,ilosc,opis,czas,dozor_prc_id) VALUES (:z,:do,:twr_id,:ilosc,:opis,now(),:dozor_prc_id)");
  58. query.bindValue(":z",ui->LE_ruchy_z_id->text());
  59. query.bindValue(":do",ui->LE_ruchy_do_id->text());
  60. query.bindValue(":twr_id",ui->LE_ruchy_twr_id->text());
  61. query.bindValue(":ilosc",QString::number(ui->SB_ruchy_ilosc->value()));
  62. query.bindValue(":opis",ui->PTE_ruchy_opis->toPlainText());
  63. query.bindValue(":dozor_prc_id",QString::number(::prc_id));
  64.  
  65. query.exec();
  66.  
  67. qDebug()<<"ruchy querry : "<<query.lastQuery();
  68. qDebug()<<"Ruchy insert : "<<query.lastError();
  69. qDebug()<<"ruchy last id: "<<query.lastInsertId().toString();
  70.  
  71. query.prepare("SELECT id from Stany where twr_id='"+ui->LE_ruchy_twr_id->text()+"' and magazyn_id='"+ui->LE_ruchy_do_id->text()+"'" );
  72. query.exec();
  73. if (query.next())
  74. {
  75. query.prepare("UPDATE Stany set stan=stan+"+QString::number(ui->SB_ruchy_ilosc->value())+" where id='"+query.value(0).toString()+"' ");
  76. query.exec();
  77. qDebug()<<"aktualizuj stan bo byl :"+query.lastQuery();
  78.  
  79. }
  80. else
  81. {
  82. query.prepare("INSERT INTO Stany (magazyn_id,twr_id,stan) VALUES ('"+ui->LE_ruchy_do_id->text()+"','"+ui->LE_ruchy_twr_id->text()+"','"+QString::number(ui->SB_ruchy_ilosc->value())+"')");
  83. query.exec();
  84. qDebug()<<"dodaj stan bo nie bylo "+query.lastQuery();
  85. qDebug()<<"stany insert : "<<query.lastError();
  86. qDebug()<<"stany last id: "<<query.lastInsertId().toString();
  87.  
  88.  
  89.  
  90. }
  91. query.prepare("UNLOCK TABLE inicio.Stany ");query.exec();
  92. qDebug()<<"unlock table : "<<query.lastError();
  93.  
  94. query.prepare("UNLOCK TABLES");query.exec();
  95. qDebug()<<"unlock tables : "<<query.lastError();
  96.  
  97.  
  98. qDebug()<<"commit : "<<query.lastError();
To copy to clipboard, switch view to plain text mode