0

在过去的 2-3 天里,我在将数据从我制作的 Qt 程序插入到 postgres 数据库时遇到问题。

我已经与数据库建立了连接,但是当我尝试插入数据时,程序向我发送了以下消息:

ERROR:  syntax error at or near "("
LINE 1: EXECUTE  ('thisIsSomeName', 4, '0000')
                 ^
QPSQL: Unable to create query

这是来自 Qt 的插入值的代码。

QSqlQuery qsql;
qsql.prepare("INSERT INTO baza(Name, ID, Birth Date)"
                     "VALUES (?, ?, ?)");

        qsql.bindValue(0, "thisIsSomeName");
        qsql.bindValue(1, 4);
        qsql.bindValue(2, "0000");

        if (qsql.exec())
        {
            label->setText("all is good");
        }

你能告诉我如何使这项工作。谢谢。巴扎脚本

CREATE TABLE baza
(
  "Name" name NOT NULL DEFAULT 50,
  "ID" integer NOT NULL,
  "Birth Date" text DEFAULT 0,
  CONSTRAINT baza_pkey PRIMARY KEY ("ID")
)
WITH (
  OIDS=FALSE
);
ALTER TABLE baza OWNER TO postgres;
4

1 回答 1

2

try this

    CREATE TABLE baza
      (
         Name  name NOT NULL DEFAULT 50,
         ID  integer NOT NULL,
         Birth_Date  text DEFAULT 0,
       CONSTRAINT baza_pkey PRIMARY KEY ("ID")
    )
     WITH (
        OIDS=FALSE
     );
       ALTER TABLE baza OWNER TO postgres;

then try this

  QSqlQuery qsql;
  qsql.prepare("INSERT INTO baza(Name, ID, Birth_Date)"
                 "VALUES (?, ?, ?)");

    qsql.bindValue(0, "thisIsSomeName");
    qsql.bindValue(1, 4);
    qsql.bindValue(2, "0000");

    if (qsql.exec())
    {
        label->setText("all is good");
    }

here are some examples sql sqlstatements

于 2012-04-05T12:41:37.843 回答