【问题标题】:Expected type utf8 for Argument 'sql' but got type 'object'参数“sql”的预期类型为 utf8,但类型为“object”
【发布时间】:2015-08-02 14:40:45
【问题描述】:

我正在尝试GNOME JavsScript tutorial,似乎是not to work in its original version

  var gdaStrConn = Gda.Connection.open_from_string("SQLite", "DB_DIR=" + GLib.get_home_dir () + ";DB_NAME=gnome_demo", null, 0);
  print('Connected');
  gdaStrConn.execute_non_select_command (this.connection, 'create table demo (id integer, name varchar(100))');

函数execute_non_select_command 的文档说:

gint                gda_connection_execute_non_select_command
                                                        (GdaConnection *cnc,
                                                         const gchar *sql,
                                                         GError **error);
This is a convenience function to execute a SQL command over the opened connection. For the returned value, see gda_connection_statement_execute_non_select()'s documentation.

cnc : an opened connection
sql : a query statement that must not begin with "SELECT"
error : a place to store errors, or NULL
Returns : the number of rows affected or -1, or -2

现在我收到以下错误:

(gjs:25295): Gjs-WARNING **: JS ERROR: Error: Expected type utf8 for Argument 'sql' but got type 'object'

为什么会出现这个错误,因为 sql 参数是一个字符串:'create table demo (id integer, name varchar(100))'?

那个电话有什么问题?

【问题讨论】:

    标签: javascript gnome gjs


    【解决方案1】:

    在第 3 行省略函数中的第一个参数,因此该行如下所示:

    gdaStrConn.execute_non_select_command ('create table demo (id integer, name varchar(100))');
    

    我不知道为什么会这样,只是自己学习 gjs。

    【讨论】:

    • 这个工作的原因是文档是针对库的 C 版本的。第一个参数,指向GdaConnection 的指针,在javascript 中表示为调用该方法的对象(即gdaStrConnection.execute_non_select_command(...) 大致相当于C 中的gda_connection_execute_non_select_command(gdaStrConnection, ...)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    相关资源
    最近更新 更多