[MDEV-9421] LOAD DATA LOCAL INFILE with 64-bit libmysql.dll will have error 1148 Created: 2016-01-15  Updated: 2016-01-20  Resolved: 2016-01-20

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Update, Platform Windows
Affects Version/s: 10.1.10
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Nick Au Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: delphi
Environment:

Windows 8.1 64-bit, any software using 64-bit libmysql.dll


Attachments: Zip Archive dll_test.zip     Zip Archive dll_test_source.zip    

 Description   

the libmysql.dll is downloaded from

https://downloads.mariadb.org/interstitial/mariadb-10.1.10/winx64-packages/mariadb-10.1.10-winx64.zip/from/http%3A//mariadb.nethub.com.hk/

Using this dll to connect to MariaDB, and set

mysql_options(
      MySQLHandle,
      MYSQL_OPT_LOCAL_INFILE,
      1);

then execute any LOAD DATA LOCAL INFILE query will have error "1148 - The used command is not allowed with this MariaDB version"

PS. 32-bit version libmysql.dll is working fine



 Comments   
Comment by Elena Stepanova [ 2016-01-16 ]

Works fine for me. My test is below.

#include <my_global.h>
#include <mysql.h>
 
 
int main(int argc, char **argv)
{  
  MYSQL *con = mysql_init(NULL);
  static uint opt_local_infile = 1;
 
  if (con == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }
 
  mysql_options(con, MYSQL_OPT_LOCAL_INFILE,&opt_local_infile);
 
  if (mysql_real_connect(con, "127.0.0.1", "root", "", 
          NULL, 0, NULL, 0) == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }  
 
  if (mysql_query(con, "LOAD DATA LOCAL INFILE 'dmp' INTO TABLE mysql.table_stats")) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }
 
  mysql_close(con);
  exit(0);
}

If it connects to a server with default local_infile server-side value, which is ON, it correctly complains about the missing data file etc. If I set local_infile=OFF on the server, or if I change the value of opt_local_infile to 0 in the test, then I get the error that you mentioned, which is expected.

Please provide a test which allows to reproduce the problem on your side.
Please also make sure that you actually use the rebuilt binary after you set the option – things happen.

Comment by Nick Au [ 2016-01-18 ]

Attached a small test. If using the libmysql.dll from mariadb-10.1.10-winx64, will have error "The used command is not allowed with this MySQL version". If replace the libmysql.dll with mysql-5.6.28-winx64 one, will complains about missing dmp file as expected.

dll_test.zip

Comment by Elena Stepanova [ 2016-01-18 ]

Please provide the source code.

Comment by Nick Au [ 2016-01-19 ]

Attached the source code. It is Delphi.

dll_test_source.zip

Comment by Elena Stepanova [ 2016-01-19 ]

Thank you.

While experimenting with your code, I encountered very confusing results
We don't have Delphi experts in our development team (in fact, nobody here ever uses Delphi at all), so we cannot interpret these observations with enough certainty, I hope you will help us with that.
While we haven't completely ruled out a library problem, it seems more likely that something goes wrong with the Delphi part.

First of all, the problem is reproducible as you described with the exact provided code – the query gets rejected on the reason that LOCAL INFILE is not allowed, with different MariaDB libraries (I tried 10.1 and 10.0, binary distribution and source builds), while it works all right with MySQL library you included into the archive.

But then it gets weird.

Issue 1

If you set LocalInfile := 0 instead of 1 in line 74, with otherwise the very same code, the problem gets reversed. Now, MariaDB library behaves correctly and the query gets rejected, while with MySQL library the value is ignored, and the query is still allowed.

Issue 2

Restore the initial code, so LocalInfile := 1;.
If you change the seemingly innocent line 70, and add 3 more symbols to the string, e.g.

    Memo1.Lines.Add('Initialize a MYSQL handle by mysql_init!!!')

while leaving everything else as is, it works fine with both MariaDB and MySQL libraries – in both cases the query is allowed.

Issue 3

Restore the initial code, no extra symbols.
If you clear Memo1.Lines right before calling mysql_options, e.g.

  LocalInfile := 1;
  Memo1.Lines.Clear;
  mysql_options(MySQLHandle, MYSQL_OPT_LOCAL_INFILE, @LocalInfile);

then again, it works correctly with both libraries – the query is allowed.

Now, I don't know what magic there is behind this TMemo thing, maybe you'll tell us – I tried to get rid of it altogether and wasn't able to, – but it seems strange that the library behavior depends on it, it seems more likely that something already goes wrong by the time when the library is used.

Since Delphi is your field, can you check it and confirm or rule it out, so we can proceed?

Comment by Nick Au [ 2016-01-20 ]

Yes, you are right. The problem is... the enum mysql_option in Delphi is defined as 2 bytes (should be 4 bytes).
Thanks you for your help.

Generated at Thu Feb 08 07:34:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.