代码拉取完成,页面将自动刷新
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
#include <QVector>
int main(int argc, char *argv[])
{
QString connectionName("playlist_connection");
QCoreApplication a(argc, argv);
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", connectionName);
db.setDatabaseName("media.db");
if(!db.open()) {
qDebug() << db.lastError();
return -1;
}
QSqlQuery query(db);
query.exec("CREATE TABLE AudioFiles ("
"path VARCHAR(255) NOT NULL,"
"modify DATETIME,"
"title VARCHAR(255),"
"artist VARCHAR(255),"
"album VARCHAR(255),"
"genre VARCHAR(255),"
"PRIMARY KEY (path)"
");");
#if 0
const QVector<QString> v({":path", ":modify", ":title", ":artist", ":album", ":genre"});
query.prepare(QString("INSERT INTO AudioFiles VALUES(%1, %2, %3, %4, %5, %6);").
arg(v[0]). arg(v[1]). arg(v[2]). arg(v[3]). arg(v[4]). arg(v[5]));
query.bindValue(v[0], "C:/Users/semisky/music/1.mp3");
query.bindValue(v[1], "2000-11-07 12:00:00");
query.bindValue(v[2], "Pretty Girl");
query.bindValue(v[3], "jay chou");
query.bindValue(v[4], "jay");
query.bindValue(v[5], "unknows");
if(!query.exec()) {
qDebug() << query.lastError();
}
#else
//Insert Row
//if one error, other querys not perform.
query.prepare("INSERT INTO AudioFiles VALUES(?, ?, ?, ?, ?, ?);");
QVariantList path, modify, title, artist, album, genre;
path << "C:/Users/semisky/music/1.mp3" << "C:/Users/semisky/music/2.mp3";
query.addBindValue(path);
modify << "2000-11-07 12:00:00" << "2000-11-07 12:00:01";
query.addBindValue(modify);
title << "Pretty Girl" << "Pretty Boy";
query.addBindValue(title);
artist << "jay chou" << "jay chou";
query.addBindValue(artist);
album << "jay" << "jay";
query.addBindValue(album);
genre << QVariant(QVariant::String) << "popluar";
query.addBindValue(genre);
if(!query.execBatch()) {
qDebug() << query.lastError();
}
#endif
//Select Row
query.exec("SELECT * FROM AudioFiles WHERE path LIKE '%mp3'");
while(query.next()) {
#if 0
qDebug() << query.record();
#else
qDebug() << query.value(0).toString() <<
query.value("modify").toString() <<
query.value(2).toString() <<
query.value(3).toString() <<
query.value(4).toString() <<
query.value(5).toString();
#endif
}
db.close();
}
QSqlDatabase::removeDatabase(connectionName);
return a.exec();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。