The situation is as follows.
I am trying to create a query to the database (MySQL database) to add a record.
I went the following way, through the parameters:

Form1.ADOQuery1.SQL.Add('INSERT INTO exam_users (`family`, `name`, `patronymic`, `birthdate`) VALUES (:family, :name, :patronymic, :birthdate)'); Form1.ADOQuery1.Parameters.ParamByName('family').Value:= Edit1.text; Form1.ADOQuery1.Parameters.ParamByName('name').Value:= Edit2.text; Form1.ADOQuery1.Parameters.ParamByName('patronymic').Value:= Edit3.text; Form1.ADOQuery1.Parameters.ParamByName('birthdate').Value:= Edit4.text; Form1.ADOQuery1.ExecSQL; 

Those. text variables were sent to the query.
They are written to the database, but with a warning window (Exception - see the picture). In the database field is also text: text .
What caused this behavior Delphi, or, more precisely, even the driver MySQL? (So ​​how do I connect via "mysql-connector-odbc-5.2.7")?
(fig.1, fig.2).

enter image description here

enter image description here

  • one
    In which line of code does the error occur? What can be seen in the MySQL log? Perhaps you have a problem with the encoding. - kot-da-vinci
  • @ kot-da-vinci, an error occurs in the Form1.ADOQuery1.SQL.Add('... Delphi line because it works from under Windows OS, according to all the rules, in the cp1251 encoding, it also feeds the data into the table. Since the data is come in a normal, readable form (in Cyrillic). - I_CaR
  • no such rules. - kot-da-vinci

1 answer 1

Before executing Form1.ADOQuery1.SQL.Add code Form1.ADOQuery1.SQL.Add what happens to Form1.ADOQuery1 ?

Perhaps there is already a sql script and you are trying to add another one.

Try to clear Form1.ADOQuery1.SQL.Clear; . But it is better to use Form1.ADOQuery1.SQL.Text := 'sql script'; - In this case, there should be no conflicts.

UPD1

We're wondering here, but in fact everything is simple. TEXT - A BLOB or TEXT column with a maximum length of 65535 (2 ^ 16 - 1) characters.

C BLOB fields work a little differently. In such fields are mainly large objects. Work with the Blob field can be viewed for example here .

You have 2 ways:

  • Change field type to Varchar
  • Teach the program to work with blob fields.

I am more inclined to the first paragraph because the name, surname .... need no more than 255 characters.

  • before add , the standard Form1.ADOQuery1.Close; Form1.ADOQuery1.SQL.Clear; Form1.ADOQuery1.Close; Form1.ADOQuery1.SQL.Clear; Tried to change to ADOQuery1.Text:= , the result is the same. - I_CaR
  • You can try to see what all the same comes to the MySQL server. Discussion here - androschuk
  • need no more than 255 characters - Programmers misconceptions about names, item number 6. kalzumeus.com/2010/06/17/… - kot-da-vinci