Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 165 lines (145 sloc) 5.192 kb
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
1 /*
2 * Copyright (C) 2005-2008 Team XBMC
3 * http://www.xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22 #include "ViewDatabase.h"
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
23 #include "utils/URIUtils.h"
24 #include "settings/Settings.h"
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
25 #include "ViewState.h"
26 #include "utils/log.h"
0a1b4b9 fixed: LINUX build errors
AlTheKiller authored
27 #ifdef _LINUX
28 #include "linux/ConvUtils.h" // GetLastError()
29 #endif
1b058de @elupus changed: reduce header dependency pollution
elupus authored
30 #include "dbwrappers/dataset.h"
31
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
32
33 //********************************************************************************************************************************
34 CViewDatabase::CViewDatabase(void)
35 {
36 }
37
38 //********************************************************************************************************************************
39 CViewDatabase::~CViewDatabase(void)
40 {
41
42 }
43
44 //********************************************************************************************************************************
e530836 added: Initial support for mysql database backend, thanks to firnsy (…
jmarshallnz authored
45 bool CViewDatabase::Open()
46 {
47 return CDatabase::Open();
48 }
49
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
50 bool CViewDatabase::CreateTables()
51 {
52 try
53 {
54 CDatabase::CreateTables();
55
56 CLog::Log(LOGINFO, "create view table");
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
57 m_pDS->exec("CREATE TABLE view ( idView integer primary key, window integer, path text, viewMode integer, sortMethod integer, sortOrder integer, skin text)\n");
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
58 CLog::Log(LOGINFO, "create view index");
59 m_pDS->exec("CREATE INDEX idxViews ON view(path)");
60 CLog::Log(LOGINFO, "create view - window index");
61 m_pDS->exec("CREATE INDEX idxViewsWindow ON view(window)");
62 }
63 catch (...)
64 {
65 CLog::Log(LOGERROR, "%s unable to create tables:%u",
66 __FUNCTION__, GetLastError());
67 return false;
68 }
69
70 return true;
71 }
72
73 bool CViewDatabase::UpdateOldVersion(int version)
74 {
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
75 if (version < 4)
76 m_pDS->exec("alter table view add skin text");
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
77 return true;
78 }
79
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
80 bool CViewDatabase::GetViewState(const CStdString &path, int window, CViewState &state, const CStdString &skin)
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
81 {
82 try
83 {
84 if (NULL == m_pDB.get()) return false;
85 if (NULL == m_pDS.get()) return false;
86
87 CStdString path1(path);
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
88 URIUtils::AddSlashAtEnd(path1);
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
89 if (path1.IsEmpty()) path1 = "root://";
90
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
91 CStdString sql;
92 if (skin.IsEmpty())
93 sql = PrepareSQL("select * from view where window = %i and path like '%s'", window, path1.c_str());
94 else
95 sql = PrepareSQL("select * from view where window = %i and path like '%s' and skin='%s'", window, path1.c_str(), skin.c_str());
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
96 m_pDS->query(sql.c_str());
97
98 if (!m_pDS->eof())
99 { // have some information
765a6f1 changed: long -> int in database functions.
jmarshallnz authored
100 state.m_viewMode = m_pDS->fv("viewMode").get_asInt();
101 state.m_sortMethod = (SORT_METHOD)m_pDS->fv("sortMethod").get_asInt();
102 state.m_sortOrder = (SORT_ORDER)m_pDS->fv("sortOrder").get_asInt();
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
103 m_pDS->close();
104 return true;
105 }
106 m_pDS->close();
107 }
108 catch (...)
109 {
110 CLog::Log(LOGERROR, "%s, failed on path '%s'", __FUNCTION__, path.c_str());
111 }
112 return false;
113 }
114
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
115 bool CViewDatabase::SetViewState(const CStdString &path, int window, const CViewState &state, const CStdString &skin)
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
116 {
117 try
118 {
119 if (NULL == m_pDB.get()) return false;
120 if (NULL == m_pDS.get()) return false;
121
122 CStdString path1(path);
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
123 URIUtils::AddSlashAtEnd(path1);
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
124 if (path1.IsEmpty()) path1 = "root://";
125
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
126 CStdString sql = PrepareSQL("select idView from view where window = %i and path like '%s' and skin='%s'", window, path1.c_str(), skin.c_str());
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
127 m_pDS->query(sql.c_str());
128 if (!m_pDS->eof())
129 { // update the view
765a6f1 changed: long -> int in database functions.
jmarshallnz authored
130 int idView = m_pDS->fv("idView").get_asInt();
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
131 m_pDS->close();
eb7123d utilise vprepare and provide a PrepareSQL() function to supersede For…
firnsy authored
132 sql = PrepareSQL("update view set viewMode=%i,sortMethod=%i,sortOrder=%i where idView=%i", state.m_viewMode, (int)state.m_sortMethod, (int)state.m_sortOrder, idView);
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
133 m_pDS->exec(sql.c_str());
134 }
135 else
136 { // add the view
137 m_pDS->close();
d6c609d @AaronDnz Implements Trac Ticket #10796 - view state stored by skin
AaronDnz authored
138 sql = PrepareSQL("insert into view (idView, path, window, viewMode, sortMethod, sortOrder, skin) values(NULL, '%s', %i, %i, %i, %i, '%s')", path1.c_str(), window, state.m_viewMode, (int)state.m_sortMethod, (int)state.m_sortOrder, skin.c_str());
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
139 m_pDS->exec(sql.c_str());
140 }
141 }
142 catch (...)
143 {
144 CLog::Log(LOGERROR, "%s failed on path '%s'", __FUNCTION__, path.c_str());
145 }
146 return true;
147 }
148
149 bool CViewDatabase::ClearViewStates(int windowID)
150 {
151 try
152 {
153 if (NULL == m_pDB.get()) return false;
154 if (NULL == m_pDS.get()) return false;
155
eb7123d utilise vprepare and provide a PrepareSQL() function to supersede For…
firnsy authored
156 CStdString sql = PrepareSQL("delete from view where window = %i", windowID);
45285e8 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
157 m_pDS->exec(sql.c_str());
158 }
159 catch (...)
160 {
161 CLog::Log(LOGERROR, "%s failed on window '%i'", __FUNCTION__, windowID);
162 }
163 return true;
164 }
Something went wrong with that request. Please try again.