0

In Lazarus, I am loading libmariadb.so.3 v3.3.10 via LoadLibrary(). (Did another test with libmysqlclient.so.21 v8.0.41). When iterating through the fields of a query result, the length of a value is indicated by the items of the array returned from mysql_fetch_lengths():

type
  PMYSQL_LENGTHS = ^TMYSQL_LENGTHS;
  TMYSQL_LENGTHS = array[0..4095] of LongWord;

  mysql_fetch_lengths: function(Result: PMYSQL_RES): PMYSQL_LENGTHS; cdecl;

var
  LengthsPointer: PMYSQL_LENGTHS;
begin
  LengthsPointer := mysql_fetch_lengths(FCurrentResults);
  for i := 0 to NumFieldsInResult - 1 do
    ShowMessage(IntToStr(LengthsPointer^[i]));

That worked for years nicely, in Delphi and also in Lazarus with a Windows executable. I am using the same libmysql and libmariadb libraries on Windows as on Linux. Now when I compile the same code in Lazarus for Linux and run it, the TMYSQL_LENGTHS seems to contain Int64 items (with a size of 8 bytes), not LongWord/UInt32 (with a size of 4 bytes). When keeping the LongWord definition, the array loop shows twice as many items as columns exist in the table, with a 0 at each odd index, e.g.:

fieldno LengthsPointer[fieldno]
0       2
1       0
2       10
3       0
4       3
5       0
6       1024
7       0

The documentation clearly states these should be unsigned long integers, even for the newest versions. So I assume I am doing something wrong. Do I?

3
  • You use a MariaDB library but read MySQL's docs? Also it can depend on the platform: long may have a default size of 32 bit when compiling for 32-bit and 64 bit for 64-bit platforms. Platforms, not operating systems. Don't mix different platforms, and don't mix vendors. Commented Mar 9 at 11:49
  • In fact the tests I did were all on 64 bit system, with a 64 bit compiler, and with libmariadb. And the MariaDB docs say basically the same as MySQL. I am just stumbling over a hint in both docs, saying "an array containing the lengths of every column [...] (not including terminating zero character) " May that terminating nul char be the crux? Commented Mar 9 at 13:36
  • As AmigoJack says, Long might be 32-bit on some 64-bit targets like e.g. Windows, where "long long" scales with pointer. Afaik some commercial Unixes did so too. Anyway, 64-bit Linux is not exactly a new target, and has been around for two decades, Mysql/mariasql is notorious for breaking APIs. It might be on their end Commented Mar 21 at 23:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.