简体   繁体   English

将数据从 qt 插入到 postgres 数据库错误

[英]Inserting data from qt to postgres database error

In last 2-3 days I am having problem with inserting data to postgres databse from Qt program I made.在过去的 2-3 天里,我在将数据从我制作的 Qt 程序插入到 postgres 数据库时遇到了问题。

I have made connection with the database, but when I try to insert data, the program sends me this message:我已经与数据库建立了连接,但是当我尝试插入数据时,程序向我发送了这条消息:

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

Here is the code from Qt that insert the value.这是插入值的 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");
        }

Can you please tell how to make this work.你能告诉我如何进行这项工作吗? Thanks.谢谢。 Script of baza巴扎的剧本

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;

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这里有一些例子sql sqlstatements

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM