sbLocalDatabaseSQL.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #include "sbLocalDatabaseSQL.h"
28 
29 #include <nsMemory.h>
30 
31 #include <sbStringUtils.h>
32 
34 
35 inline
36 nsString ExtractColumnFromProperty(sbStaticProperty const & aProperty)
37 {
38  return NS_ConvertASCIItoUTF16(aProperty.mColumn);
39 }
40 
45 inline
46 nsString Concat(nsAString const & aLeft, nsAString const & aRight)
47 {
48  nsString temp(aLeft);
49  temp.Append(aRight);
50  return temp;
51 }
52 
53 static
55 {
56  nsString result;
57  NS_NAMED_LITERAL_STRING(COMMA, ",");
58 
59  for (PRUint32 property = 0; property < NS_ARRAY_LENGTH(sStaticProperties); ++property) {
60  if (property != 0) {
61  result.Append(COMMA);
62  }
63  result.AppendLiteral(sStaticProperties[property].mColumn);
64  }
65  return result;
66 }
67 
68 nsString sbLocalDatabaseSQL::MediaItemColumns(PRBool aIncludeMediaItem)
69 {
70  if (mMediaItemColumns.IsEmpty()) {
71  mMediaItemColumns= sbStaticPropertyColumns();
72  }
73  if (mMediaItemColumnsWithID.IsEmpty()) {
74  mMediaItemColumnsWithID = Concat(NS_LITERAL_STRING("media_item_id, "),
75  mMediaItemColumns);
76  }
77  return aIncludeMediaItem ? mMediaItemColumnsWithID : mMediaItemColumns;
78 }
79 
81 {
82  nsString sql =
83  NS_LITERAL_STRING("SELECT media_item_id, property_id, obj \
84  FROM resource_properties \
85  WHERE media_item_id IN (");
86  for (int i = 0; i < sbLocalDatabaseSQL::SecondaryPropertyBindCount-1; i++) {
87  sql.AppendLiteral("?, ");
88  }
89  sql.AppendLiteral("?)");
90 
91  return sql;
92 }
93 
95 {
96  nsString sql = NS_LITERAL_STRING("DELETE FROM resource_properties_fts_all \
97  WHERE rowid = ?");
98  return sql;
99 }
100 
102 {
103  nsString result(NS_LITERAL_STRING("SELECT "));
104  result.Append(MediaItemColumns(PR_TRUE));
105  result.AppendLiteral(" FROM media_items WHERE guid IN (");
106  for (int i = 0; i < sbLocalDatabaseSQL::MediaItemBindCount-1; i++) {
107  result.AppendLiteral("?, ");
108  }
109  result.AppendLiteral("?)");
110 
111  return result;
112 }
113 
115 {
116  nsString sql =
117  NS_LITERAL_STRING("INSERT INTO resource_properties_fts_all \
118  (rowid, alldata) VALUES (?, ?)");
119  return sql;
120 }
121 
123 {
124  return NS_LITERAL_STRING("SELECT property_id, obj \
125  FROM resource_properties \
126  WHERE media_item_id = 0");
127 }
128 
130 {
131  if (mLibraryMediaItemSelect.IsEmpty()) {
132  mLibraryMediaItemSelect.AppendLiteral("SELECT ");
133  mLibraryMediaItemSelect.Append(MediaItemColumns(PR_FALSE));
134  mLibraryMediaItemSelect.AppendLiteral(" FROM library_media_item");
135  }
136  return mLibraryMediaItemSelect;
137 }
138 
140 {
141  return NS_LITERAL_STRING("INSERT INTO properties \
142  (property_name) \
143  VALUES (?)");
144 }
145 
147 {
148  return NS_LITERAL_STRING("SELECT property_id, property_name \
149  FROM properties");
150 }
151 
153 {
154  return NS_LITERAL_STRING("INSERT OR REPLACE INTO resource_properties \
155  (media_item_id, property_id, obj, obj_searchable, obj_sortable, obj_secondary_sortable) \
156  VALUES (?, ?, ?, ?, ?, ?)");
157 }
158 
159 
161 {
162  return NS_LITERAL_STRING("DELETE FROM resource_properties WHERE media_item_id = ? AND property_id = ? ");
163 }
164 
static const int MediaItemBindCount
static nsString PropertiesDelete()
static nsString MediaItemsFtsAllDelete()
static nsString MediaItemsFtsAllInsert()
static nsString PropertiesTableInsert()
static const int SecondaryPropertyBindCount
static nsString PropertiesInsert()
nsString Concat(nsAString const &aLeft, nsAString const &aRight)
static nsString sbStaticPropertyColumns()
restoreDimensions aLeft
static nsString LibraryMediaItemsPropertiesSelect()
static nsString PropertiesSelect()
static nsString SecondaryPropertySelect()
static sbStaticProperty sStaticProperties[]
_getSelectedPageStyle s i
nsString ExtractColumnFromProperty(sbStaticProperty const &aProperty)