Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPSQL: Unable to create query, image bytea
QtWS25 Last Chance

QPSQL: Unable to create query, image bytea

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    killown
    wrote on last edited by killown
    #1

    I am trying trying to insert images into tables but I get this error:

    "INSERT INTO Registrations.Customer_Picutre (name, image) VALUES (?, ?)"
    QSqlError("42601", "QPSQL: Unable to create query", "ERROR: syntax error at or near "("\nLINE 1: EXECUTE ('asdf', '\xffd8ffe000104a4649460001010100600060000...\n ^\n(42601)")
    "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL

    any idea in what's wrong in my code?

    query.exec("CREATE EXTENSION citext;");
    query.exec("CREATE SCHEMA Registrations;");
    query.exec("create table Registrations.Customer_Picture"
              "(colname SERIAL primary key, "
              "name  CITEXT, "
              "image  bytea)");
    QString folder = QCoreApplication::applicationDirPath() + "/images";
    QString img = folder + "/new.jpg";
    QFile* file = new QFile(img);
    file->open(QIODevice::ReadOnly);
    QByteArray image = file->readAll();
    QString encoded = QString(image.toBase64());
    
    //insert picture
    query.prepare("INSERT INTO Registrations.Customer_Picutre (name, image) "
                  "VALUES (:name, :image)");
    query.bindValue(":name", ui->name_lineEdit_mainData->text());
    query.bindValue(":image", encoded, QSql::In | QSql::Binary);
    
    query.exec();
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Your query syntax is wrong. Please check it. Many sql query syntax checkers in google. Copy paste ur query and check it before placing in code. You can also check ur query sql command prompt of ur da.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • K Offline
        K Offline
        killown
        wrote on last edited by
        #3

        sorry the irror is INSERT INTO Registrations.Customer_Picutre which should be INSERT INTO Registrations.Customer_Picture

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved