-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconnection.h
86 lines (78 loc) · 3.22 KB
/
connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONNECTION_H
#define CONNECTION_H
#include<QSqlDatabase>
#include<QSqlQuery>
#include<QMessageBox>
#include<QApplication>
#include<QSqlError>
static bool CreatConnection()
{
QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
QString dirPath = QString(getenv("HOME")) + "/.kylin-music";
db.setDatabaseName(dirPath + "mymusic.db");
if(!db.open())
{
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
QSqlQuery query;
// query.exec(QString("drop table LocalMusic"));
// query.exec(QString("drop table NewPlayList"));
// query.exec(QString("drop table HistoryPlayList"));
// query.exec(QString("drop table SearchPlayList"));
query.exec(QString("create table if not exists LocalMusic ("
"hash varchar primary key not null,"
"musicname varchar,"
"filepath varchar,"
"singer varchar,"
"album varchar,"
"type varchar,"
"size varchar,"
"time varchar)"
));//本地音乐列表数据
query.exec(QObject::tr("create table if not exists NewPlayList ("
// "playlistid int primary key,"
"listname varchar primary key,"
"musicid varchar)"
));//添加新歌单
query.exec(QString("insert into NewPlayList (listname,musicid) values ('我喜欢','')"));
// query.exec(QString("create table if not exists LikeMusic ("
// "hash varchar primary key not null,"
// "time varchar)"
// ));//
query.exec(QString("create table if not exists HistoryPlayList ("
"id int primary key,"
"mp3Name varchar,"
"artistStr varchar,"
"timeStr varchar)"
));//历史播放列表
// query.exec(QString("create table if not exists SearchPlayList ("
// "id int primary key,"
// "musicname varchar,"
// "filepath varchar,"
// "singer varchar,"
// "album varchar,"
// "type varchar,"
// "size varchar,"
// "time varchar)"
// ));//搜索列表
return true;
}
#endif // CONNECTION_H