Skip to content
QtWS25 Last Chance
  • 0 Votes
    14 Posts
    1k Views
    J
    @JonB I do not understand anything. Please could you give more informantion. Note : app release folder has [image: 4eb83936-1e08-43aa-adf2-7623432feb91.png] I solved the problem :) I add lib files from Postgresql to release folder [image: 9264bc86-4743-4f27-8db5-6abb3fe4b395.png] and it works. thank you @jsulm and @JonB
  • 0 Votes
    1 Posts
    322 Views
    No one has replied
  • 0 Votes
    13 Posts
    1k Views
    jsulmJ
    @PMime Sounds like "describe" statement is what you need, see https://www.geeksforgeeks.org/sql-describe-statement/
  • 0 Votes
    5 Posts
    887 Views
    sierdzioS
    Unless you have some hardcore use case, perhaps you don't need to cache at all? SQLite is pretty fast, and Qt comes with QSqlQueryModel / TableModel helper classes. In my (limited :D) experience, it works really well and fast, even on slow hardware.
  • Can't write into database

    Unsolved General and Desktop qsqldatabase qsql qml
    14
    0 Votes
    14 Posts
    2k Views
    artwawA
    @Babs Anytime. Please don't forget to mark the thread as "solved".
  • build MySQL driver on ubuntu 18.04

    Unsolved General and Desktop qsql ubuntu 18.04
    10
    0 Votes
    10 Posts
    1k Views
    mrjjM
    Hi Just to make sure you understand. When you install Qt from Qt site you get the normal version. However, Unbuntu also allows you to use apt-get an Qt version. ( often Not the newest but close) If you use that version, then you can also apt-get thd MySql stuff that is compiled with the unbuntu version of Qt. So ifs not critical to use the absolute newest Qt then Remove the version from Qt site and apt-get Qt from ubuntu and the MySql Stuff and it should just work with no extra effort.
  • Store custom QVariant type in database

    Solved General and Desktop qsql qsqlquery qvariant
    6
    0 Votes
    6 Posts
    2k Views
    JKSHJ
    @Max13 said in Store custom QVariant type in database: I will write a toJson() instead, as I'm loading the data from Json already. Sounds good. Thanks for your advice. Indeed, it would be the correct way to implement this, in my situation I didn't think it would be necessary to implement it that way. I'm updating some models from an API, and save them as a read-only cache in an sqlite because the desktop may be disconnected. So in my opinion, adding another table would make me write more queries and deal with relations when I can do that in a nasty way 😅 That's fair enough. Simplicity is often a good thing in code. Thanks for your complete answer. You're most welcome. Happy coding!
  • 0 Votes
    1 Posts
    405 Views
    No one has replied
  • create Excel file QSqlDatabase open error

    Solved General and Desktop qsql excel
    7
    0 Votes
    7 Posts
    3k Views
    C
    It's Ok, i found the problem. I have to define the full path DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)} to avoid the error message
  • QtSql - Data source name not found..

    Solved General and Desktop qsqlerror qodbc qsql
    5
    0 Votes
    5 Posts
    6k Views
    SGaistS
    Great ! Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)
  • 0 Votes
    16 Posts
    8k Views
    SGaistS
    Duplicating connection name means that you will break at least one connection. I'd rather not overlook that.
  • 0 Votes
    18 Posts
    13k Views
    M
    Thank you very much @SGaist and @raven-worx for helping me out. I fixed this issue by using runtime libraries from this project: https://sourceforge.net/projects/postgresql-mingw-w64/
  • 1 Votes
    8 Posts
    6k Views
    kshegunovK
    @maurosanjo Well, I'm all out of ideas, sorry.
  • 0 Votes
    2 Posts
    2k Views
    P
    Hello, I don't think it's that simple as you try to make it, at least if you want to include the data too. Few years ago I had a similar problem and I wrote a function for that purpose. I'm copying-pasting the code from my old post after some reformatting to be readable. Although I have improved the code a bit since then in my own app, this should help you get started (please check the indentation, some fixes may be needed). This function doesn't transfer the schema, but I think it's easy to include it. void DbManager::exportTables() { QHash<QString,QStringList> tablesWithFields; //It holds the table name and its fields QStringList tables = sourceDb.tables(); QSqlQuery query(sourceDb); foreach(const QString &table,tables) { query.exec(QString("PRAGMA TABLE_INFO(%1)").arg(table)); QStringList fields; while(query.next()) { fields << query.value(1).toString(); } tablesWithFields.insert(table,fields); } QFile f(QDir::homePath() + "/myDump.sql"); f.open(QIODevice::Append | QIODevice::Text); QTextStream streamer(&f); //If constraints can't be dropped in the target database, some reordering of //the INSERT statements may be needed QStringList sortedTables = tablesWithFields.keys(); sortedTables.move(sorted.indexOf("table1"),0); ... streamer << "BEGIN;\n"; foreach(const QString &table,sortedTables) { if(table=="sqlite_sequence" /*|| table=="table4", etc*/) continue; QString statement = QString("INSERT INTO %1 VALUES('").arg(table); QStringList fields = tablesWithFields.value(table); QString fieldsString = fields.join(","); query.exec(QString("SELECT %1 FROM %2").arg(fieldsString).arg(table)); if(!query.next()) continue; query.previous(); while(query.next()) { for(int i=0; i < fields.size(); ++i) { QString value = query.value(i).toString(); value.replace("'","''"); //Handle single quotes inside strings if(value.isEmpty()) { value = "NULL"; statement.chop(1); //NULL should not appear inside quotes statement.append(value+",'"); } else { statement.append(value+"','"); } } statement.chop(2); //Remove comma and single quote from the end of value group statement.append("),('"); //Close the value group and start a new one } statement.chop(3);//Remove comma, opening parenthesis, single quote from the end streamer << statement << ";\n"; //Complete the INSERT statement } streamer << "COMMIT;"; f.close(); } And then batch execute the sql file like this: ... exportTables(); QSqlQuery query(targetDb); QFile f(QDir::homePath()+"/myDump.sql"); f.open(QIODevice::ReadOnly | QIODevice::Text); if(!query.exec(f.readAll())) qCritical() << "Can't execute sql file: " << query.lastError().text();
  • Help with SQL Query

    Unsolved General and Desktop query sql qsql
    7
    0 Votes
    7 Posts
    2k Views
    SGaistS
    lastQuery should return the actually query that ran against the database, that one would be interesting to see. Good point of @paul-colby
  • QSqlQuery error

    Solved General and Desktop qsql error
    3
    0 Votes
    3 Posts
    2k Views
    G
    Thank you. it worked.
  • 0 Votes
    5 Posts
    4k Views
    AlbertoA
    At the end it was a typo. I was trying to insert a value into a column called Localización by using: guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (Localizacion) The problem is in the accent mark. So if anyone gets this error, watch out the typos. Thanks @clochydd !
  • Understanding memory leak

    General and Desktop qwidget qsql
    1
    0 Votes
    1 Posts
    771 Views
    No one has replied
  • 0 Votes
    3 Posts
    5k Views
    AlbertoA
    Al final guardando cada valor de las dos bases de datos en QStrings funcionaba: QString _Telefono = seleccionar2.value(8).toByteArray().constData(); QString _Tecnico_Asignado = seleccionar2.value(0).toByteArray().constData(); QString _Estado_Solicitud = seleccionar2.value(7).toByteArray().constData(); Así podía usar este código sin problema: QSqlQuery guardar_s; guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (N_Solicitud, Fecha_Emision, Unidad_Hospitalaria," "Codigo_Equipo, Equipo, Marca)" "VALUES (:N_Solicitud, :Fecha_Emision, :Unidad_Hospitalaria, :Codigo_Equipo, :Equipo," ":Marca)"); guardar_s.bindValue(":N_Solicitud", _N_Solicitud); guardar_s.bindValue(":Fecha_Emision", _Fecha_Emision); guardar_s.bindValue(":Unidad_Hospitalaria", _Unidad_Hospitalaria); guardar_s.bindValue(":Codigo_Equipo", _Codigo_Equipo); guardar_s.bindValue(":Equipo", _Equipo); guardar_s.bindValue(":Marca", _Marca); Insertaba los valores de las dos bases de datos en la base Empresa, pero si usaba este otro con más valores no funcionaba: QSqlQuery guardar_s; guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (N_Solicitud, Fecha_Emision, Unidad_Hospitalaria, Codigo_Equipo," "Equipo, Marca, Modelo, N_Serie, Localizacion, Unidad_Tecnica, Peticionario, Telefono, " "Descripcion_Solicitud, Tecnico_Asignado, Tipo_Solicitud, Estado_Solicitud) " "VALUES (:N_Solicitud, :Fecha_Emision, :Unidad_Hospitalaria, :Codigo_Equipo, :Equipo, :Marca, :Modelo," ":N_Serie, :Localizacion, :Unidad_Tecnica, :Peticionario, :Telefono, :Descripcion_Solicitud," ":Tecnico_Asignado, :Tipo_Solicitud, :Estado_Solicitud)"); guardar_s.bindValue(":N_Solicitud", _N_Solicitud); guardar_s.bindValue(":Fecha_Emision", _Fecha_Emision); guardar_s.bindValue(":Unidad_Hospitalaria",_Unidad_Hospitalaria); guardar_s.bindValue(":Codigo_Equipo", _Codigo_Equipo); guardar_s.bindValue(":Equipo", _Equipo); guardar_s.bindValue(":Marca", _Marca); guardar_s.bindValue(":Modelo", _Modelo); guardar_s.bindValue(":N_Serie", _N_Serie); guardar_s.bindValue(":Localizacion", _Localizacion); guardar_s.bindValue(":Unidad_Tecnica", _Unidad_Tecnica); guardar_s.bindValue(":Peticionario", _Peticionario); guardar_s.bindValue(":Telefono", _Telefono); guardar_s.bindValue(":Descripcion_Solicitud", _Descripcion_Solicitud); guardar_s.bindValue(":Tecnico_Asignado", _Tecnico_Asignado); guardar_s.bindValue(":Tipo_Solicitud", "a"); guardar_s.bindValue(":Estado_Solicitud", _Estado_Solicitud); Me daba el error: 12.ERROR: QSqlError("", "Parameter count mismatch", ""). Pensaba que quizás eran demasiados valores para Qt Creator. Pero al final, después de muchas pruebas me dí cuenta que estaba intentando insertar un valor en la columna existente Localización con un INSERT INTO Solicitudes_Trabajo (Localizacion). Lo explico por si a alguien más le sale ese mismo error que pruebe a revisar todos los campos y columnas en busca de algún pequeño fallo en alguna letra o alguna tilde.
  • 0 Votes
    6 Posts
    5k Views
    SGaistS
    Re-building the plugin to use your currently installed libmysqlclient_r would be the simple and easy path. Just grab the sources and follow the instruction in the database part of Qt's documentation.