2

我正在通过我在 Lazarus/Freepascal 中制作的连接器查询我的数据库。它使用libmysqlfrom MySQL 5.0。据我所知,我可以调用的函数与MYSQL C Connector.

该数据库不用于远程访问;它是一个管道可访问的数据库,我正在尝试使用仅内存表(noMyISAMInnoDB)针对本地读取进行优化。速度是主要焦点。

客户端应用程序是用一种称为 MQL4(用于金融市场)的有限脚本语言编写的,并使用我的库重复查询数据库并返回结果以供分析。

问题是:每次发送新查询时,我都被迫销毁并重新创建与数据库的连接。

如果我不销毁并重新创建连接,我将遇到读取访问冲突,因为我的连接器库丢失了*MYSQL分配的值mysql_real_connect()

我会通过我的客户端应用程序传递这个值,但不幸的是,它是用一种只能处理、、和数据类型的语言LongInt编写DoubleString

我试图通过我的客户端应用程序将值传递给 to LongInt,然后将其转换回*MYSQL我的库中,但这不起作用。

老实说,我不明白为什么我的图书馆失去了*MYSQL.

这是我的图书馆代码:

{$CALLING STDCALL}

library D1Query;

{$mode objfpc}{$H+}

uses
  cmem, Windows, SysUtils, mysql50;

var
  sock: PMYSQL;
  qmysql: st_mysql;

type
  VArray = array[0..100] of Double;
  PArray = ^VArray;

  procedure InitSQL; stdcall;
  begin
    sock := mysql_real_connect(PMysql(@qmysql), '.', 'root', 'password'
                     , 'data', 3306, 'mysql', CLIENT_MULTI_STATEMENTS);
    if sock = nil then begin
      OutputDebugString(PChar('  Couldn''t connect to MySQL.'));
      OutputDebugString(PChar(mysql_error(@qmysql)));
      halt(1);
    end;
  end;

  procedure DeInitSQL; stdcall;
  begin
    mysql_close(sock);
  end;

  function SQL_Query(QRY: PChar; output: PArray): integer; stdcall;
  var
    rowbuf: MYSQL_ROW;
    recbuf: PMYSQL_RES;
    i: integer;
    nfields: LongWord;
  begin
    if (mysql_query(sock, QRY) < 0) then begin
      OutputDebugString(PChar('  Query failed '));
      OutputDebugString(PChar('   ' + mysql_error(sock)));
    end;

    recbuf := mysql_store_result(sock);
    nfields :=  mysql_num_fields(recbuf);
    rowbuf := mysql_fetch_row(recbuf);

    if (rowbuf <> nil) then begin
      for i:=0 to nfields-1 do
          output^[i] := StrToFloatDef(rowbuf[i], -666);
    end;

    mysql_free_result(recbuf);
    Result := i;   
  end;

exports
  SQL_Query, InitSQL, DeInitSQL;

begin
end.
4

1 回答 1

1

Mike,我建议使用 ZEOS 6.6.6 连接到 MySQL。

这样你就不必乱搞低级代码,但你可以使用标准的 ZEOS 控件:TZConnection TZQuery等等。

这是 Lazarus 中 ZEOS 的 Howto:http
: //wiki.lazarus.freepascal.org/Zeos_tutorial 您可以在此处下载 ZEOS 包:http
: //sourceforge.net/projects/zeoslib/files/Zeos%20Database%20Objects/ zeosdbo-6.6.6-stable/ZEOSDBO-6.6.6-stable.zip/download
下载 zip 文件并安装 lazarus 的软件包。

帮助文件可以在这里找到:http: //sourceforge.net/projects/zeoslib/files/Zeos%20Database%20Objects/zeosdbo-6.6.6-stable/

祝你好运。

于 2011-05-29T20:15:02.663 回答