Unsolved Saving to SQLite from text edit (help pwetty pwease)
-
@p3c0 Thanks, but what if I want to use the same database throughout many functions?
how do I pass the db variable to open? -
@Scottish_Jason That is what is default connection. It is available across all functions or classes. Just use
QSqlQuery
directly or you can also tryQSqlQuery query(QSqlDatabase::database())
in this case it will return the default one.
-
well guys, thanks for the help but I think I really need to hang up the hat on this one... no matter how I try to initialize the database on a second function ( or lack of initilization) I either get database not open or duplicate database open that causes instability and crashes.
I have been up all night trying to get it working so maybe I'm just tired but I'm starting to think this might be a bit over my head. Thanks for the help guys
-
@Scottish_Jason I would suggest you to start from some simple examples keeping the earlier example code in mind ofcourse after some sleep. It works :)
-
The strange thing is I am only implementing this block once in my loadsensors() function
QString dbname = "sensors"; QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("sensors.sqlite"); QSqlQuery query(QSqlDatabase::database());
and then just QSqlQuery query; in the following functions but it still insists that the database is locked.
( I need query defined so I can do the prepare's etc on each function )I probably sound awfully silly right now but I'm kinda struggling coming from a php mainly background to this. Any hints down the correct path would be appreciated
-
@Scottish_Jason
Hi, what happens, if you declare your query that way:QSqlQuery query; ... query = QSqlQuery(db);
-
You are using DB Browser for SQLite parallel - is there a chance that it locks your database?
-
@clochydd said:
You are using DB Browser for SQLite parallel - is there a chance that it locks your database?
YAYYY thanks so much.
the browser itself was the culprit. Values are being updated now.Thank you all +reps
one last question if I may:
instead of dropping the data into the 'FC-28' column I would like it to drop it under the name of whatever is selected on another table, any help in that direction?
query.prepare("UPDATE sensors SET pin1 = :dp, attached_gpio = :cp WHERE sensor_name = "selected item on sensor_table");
query.bindValue(":dp", dp1);
query.bindValue(":cp", cp1 ); -
@Scottish_Jason Do it in the same way which you did for the other placeholders viz. for eg.
:dp
and:cp
in your example. -
@Scottish_Jason
Hi Jason, may look like:QString mySearch; ... mySearch = "FC-28"; query.prepare("UPDATE sensors SET pin1 = :dp, attached_gpio = :cp WHERE sensor_name = :search;"); query.bindValue(":dp", dp1); query.bindValue(":cp", cp1 ); query.bindValue(":search", mySearch );