zoukankan      html  css  js  c++  java
  • delphi odbc 连接 mysql数据库时一次运行多条SQL语句的方法

    1,问题缘起

    某个delphi程序使用odbc驱动,通过adoConnection连接mySQL数据库。

    程序启动时,若数据库不存在则需要创建数据库及其中的表。

    建表SQL在navicat中运行无误,但在delphi程序中运行出错:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'XX' at line 

    2,问题分析

    网上查资料得知,adoConnection连接mySQL数据库,默认只能运行一条SQL语句,不能执行多条语句。即使是将多条语句中的分隔符号(;)去掉也不行。

    那么,如何让adoConnection支持一次运行多条SQL语句呢?网上提到如下解决方案:

    • 在MySQL的连接字符串中设置allowMultiQueries参数置为true
    • 设置 ODBC -- 配置 --Detials -- Flags 3 -- 钩上 Allow multiple statements
    • 打开 MySQL Connector/ODBC Data Source Configuration 在 Connection 中找到一条设置 Allow multiple statements,勾上此项

    但上述方法对使用adoConnection的delphi程序均不适用。

    3,解决方案

    https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html

    到上述mySQL的官网上查看 ODBC Connection Parameters 的设置,

    其中option 有 MULTI_STATEMENTS设置选项 67108864。因此,

    ConnectionString := 'Driver={MySQL ODBC 5.1 Driver};Server=192.168.0.2;Port=3306;Database=pgis;User=root;Password=mysql;Option=3;';

    改为

    ConnectionString := 'Driver={MySQL ODBC 5.1 Driver};Server=192.168.0.2;Port=3306;Database=pgis;User=root;Password=mysql;Option=67108864;';

    再次运行程序,建库建表成功!

  • 相关阅读:
    构建之法作业要求 20160922
    构建之法作业截止 20160908
    作业成绩 20160901
    动态范围理解
    解像力理解以及单位换算;
    QT:基本知识(一);
    qml: 截图(单窗口);
    (转载)python: getopt的使用;
    python: with的使用;
    qml: 自定义输入框
  • 原文地址:https://www.cnblogs.com/jackkwok/p/12835878.html
Copyright © 2011-2022 走看看