Topic: mysql insert script

Hi, can someone please help me with correct syntax pls?
I cant make it work... i want to insert to table via script because i need to manipulate 2 different tables in one button which i cant do in gui.

SQLExecute('INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,deliver,pickup,id_user) VALUES ("' + qcnt + "','" + qcus + "','" + qdte + "','" + qtot + "','" + qten + "','" + qchn + "','" + qdnt + "','" + qchr + "','" + qpup + "','" +  qnme + '")');

values are variable i convert to proper type StrToFloat, StrToInt etc...
I keep on receiving error') ' expected....

Re: mysql insert script

rhyacm wrote:

Hi, can someone please help me with correct syntax pls?
I cant make it work... i want to insert to table via script because i need to manipulate 2 different tables in one button which i cant do in gui.

SQLExecute('INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,deliver,pickup,id_user) VALUES ("' + qcnt + "','" + qcus + "','" + qdte + "','" + qtot + "','" + qten + "','" + qchn + "','" + qdnt + "','" + qchr + "','" + qpup + "','" +  qnme + '")');

values are variable i convert to proper type StrToFloat, StrToInt etc...
I keep on receiving error') ' expected....

" '  ' "

Re: mysql insert script

sibprogsistem wrote:
rhyacm wrote:

Hi, can someone please help me with correct syntax pls?
I cant make it work... i want to insert to table via script because i need to manipulate 2 different tables in one button which i cant do in gui.

SQLExecute('INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,deliver,pickup,id_user) VALUES ("' + qcnt + "','" + qcus + "','" + qdte + "','" + qtot + "','" + qten + "','" + qchn + "','" + qdnt + "','" + qchr + "','" + qpup + "','" +  qnme + '")');

values are variable i convert to proper type StrToFloat, StrToInt etc...
I keep on receiving error') ' expected....

" '  ' "

Thank you for response. i cant make it work , i change it to this
SQLExecute("INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,delivery,pickup,id_user) VALUES ('" + qcnt + "', '" + qcus + "', '" + qdte + "', '" + qtot + "', '" + qten + "', '" + qchn + "', '" + qdnt + "', '" + qchr + "', '" + qpup + "', '" +  qnme + "')");

Im still receiving  ')' expected
i do like this " ', ' "
maybe i dont really understand how this works but i like learning SQL query.
Is there a way to save into two tables by using only one button so i dont have to build sql query?
Thanks again for answering

Re: mysql insert script

Check it out

      SQLExecute('INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,delivery,pickup,id_user) VALUES ("' + qcnt + '", "' + qcus + '", "' + qdte + '"," ' + qtot + '"," ' + qten + '"," ' + qchn + '"," ' + qdnt + '", "' + qchr + '", "' + qpup + '", "' +  qnme + '")');
Dmitry.

Re: mysql insert script

DriveSoft wrote:

Check it out

      SQLExecute('INSERT INTO Customer (count,id_customer,date,due,payed,balance,discount,delivery,pickup,id_user) VALUES ("' + qcnt + '", "' + qcus + '", "' + qdte + '"," ' + qtot + '"," ' + qten + '"," ' + qchn + '"," ' + qdnt + '", "' + qchr + '", "' + qpup + '", "' +  qnme + '")');

Thank you for the sample i really appreciate it! This syntax do not return the error ')' expected, but i have another problem, Incompatible types...
my data come from edit box or labels. I declare Variables as real, double or string depends on value, then I pass the value of text and labels to variable using StrToFloat, StrToInt etc.
Running it return Incompatible types, but when I declare all my variable as string it run without issue, but upon executing the code, the exe crashed. Maybe due to incompatible type in mysql which are Int, double and datetime.
I tried returning one variable to double or real, also removing single quote, etc.. and it flag this point as incompatible.
Im able to create a system for what i need like a pro using visual database but im stuck now the whole day with this inserting thing..
How can i completely save my data pls?

6 (edited by sibprogsistem 2019-03-05 19:01:29)

Re: mysql insert script

example

 procedure frmReceivinOgEquipment_bOkCompany_OnClick (Sender: TObject; var Cancel: boolean);

 var tTypeKC : string = IntToStr(frmReceivinOgEquipment.cbTCK.DbItemID);
     tNameCompany : string = IntToStr(frmReceivinOgEquipment.cbNameCompany.DbItemID);
     tNameTypeOfEquipment : string = IntToStr(frmReceivinOgEquipment.cbNameTypeOfEquipment.DbItemID);
     tNameManufacturer : string = IntToStr(frmReceivinOgEquipment.cbNameManufacturer.DbItemID);
     tDate : string = FormatDateTime('yyyy-mm-dd',frmReceivinOgEquipment.dtDateInServise.DateTime);
     tCompanyOrApp : string = IntToStr(frmReceivinOgEquipment.cbnameclCompanyOrApp.DbItemID);
     tStatusName : string = IntToStr(frmReceivinOgEquipment.cbStatusName.DbItemID);
     tCount : string;
     sWarranty: string = frmReceivinOgEquipment.cbWarranty.sqlValue;
     sOnlyDiagnostic: string = frmReceivinOgEquipment.cbOnlyDiagnostic.sqlValue;
    begin
      tCount := frmReceivinOgEquipment.RecordCount.Text;
      //проверка на заполнение полей
      if (tTypeKC='-1') then ShowHint(frmReceivinOgEquipment.cbTCK, mess13)else
      if (tDate='-1') then ShowHint(frmReceivinOgEquipment.dtDateInServise, mess13)else
      if (tNameCompany='-1') then ShowHint(frmReceivinOgEquipment.cbNameCompany, mess13)else
      if (tNameTypeOfEquipment='-1') then ShowHint(frmReceivinOgEquipment.cbNameTypeOfEquipment, mess13)else
      if (tNameManufacturer='-1') then ShowHint(frmReceivinOgEquipment.cbNameManufacturer, mess13)else
      if (frmReceivinOgEquipment.eModel.Text='') then ShowHint(frmReceivinOgEquipment.eModel, mess13)else
      if (frmReceivinOgEquipment.eSerialNamber.Text='') then ShowHint(frmReceivinOgEquipment.eSerialNamber, mess13)else
      if (frmReceivinOgEquipment.eEquipment.Text='') then ShowHint(frmReceivinOgEquipment.eEquipment, mess13)else
      if (frmReceivinOgEquipment.mDescriptionATCsWords.Text='') then ShowHint(frmReceivinOgEquipment.mDescriptionATCsWords, mess13)else
      if (frmReceivinOgEquipment.mExternalStatus.Text='') then ShowHint(frmReceivinOgEquipment.mExternalStatus, mess13)else
    begin
      // запись в таблицы базы данных
      SQLExecute('INSERT INTO servise (dateInServise, id_status, id_Company, id_TypeOfEquipment, id_manufacturer, model, serialNamber, equipment, externalStatus, descriptionATCsWords, id_clCompanyOrApp, record_count, warranty, onlyDiiagnostics) VALUES ("'+tDate+'", "'+tStatusName+'", "'+tNameCompany+'", "'+ tNameTypeOfEquipment + '", "'+tNameManufacturer+'", "'+frmReceivinOgEquipment.eModel.Text+'", "'+frmReceivinOgEquipment.eSerialNamber.Text+ '", "'+frmReceivinOgEquipment.eEquipment.Text+ '", "'+ frmReceivinOgEquipment.mDescriptionATCsWords.Text+ '", "'+ frmReceivinOgEquipment.mExternalStatus.Text+ '", "'+tCompanyOrApp+'", "'+tCount+'", "'+sWarranty+'", "'+sOnlyDiagnostic+'")');
          // обновление таблицы данных главной формы
      frmServiceCen.tgList.dbUpdate;
      frmReceivinOgEquipment.RecordCount.Text := IntToStr(GetNewRecordCount('servise'));
      //закрытие формы
      frmReceivinOgEquipment.Close;
  end;
end;
tNameCompany : string = IntToStr(frmReceivinOgEquipment.cbNameCompany.DbItemID); // Combobox
 sWarranty: string = frmReceivinOgEquipment.cbWarranty.sqlValue; //  check Box
tDate : string = FormatDateTime('yyyy-mm-dd',frmReceivinOgEquipment.dtDateInServise.DateTime); // Date

Re: mysql insert script

Thank you for the help it is working now!