33 #include <nsComponentManagerUtils.h>
34 #include <nsThreadUtils.h>
37 #include <sbIDatabaseQuery.h>
38 #include <sbIDatabaseResult.h>
39 #include <sbIDatabasePreparedStatement.h>
41 #define SB_DBQUERY_CONTRACTID "@songbirdnest.com/Songbird/DatabaseQuery;1"
54 NS_ENSURE_SUCCESS(rv, rv);
56 rv = mDBQuery->SetAsyncQuery(PR_FALSE);
57 NS_ENSURE_SUCCESS(rv, rv);
59 rv = mDBQuery->SetDatabaseGUID(NS_LITERAL_STRING(
"songbird"));
60 NS_ENSURE_SUCCESS(rv, rv);
63 sql.AppendLiteral(
"CREATE TABLE IF NOT EXISTS itunes_id_map "
64 "(itunes_id TEXT UNIQUE NOT NULL, "
65 "songbird_id TEXT UNIQUE NOT NULL)");
66 rv = mDBQuery->AddQuery(sql);
67 NS_ENSURE_SUCCESS(rv, rv);
70 rv = mDBQuery->Execute(&dbOK);
71 NS_ENSURE_SUCCESS(rv, rv);
72 NS_ENSURE_TRUE(dbOK == 0, NS_ERROR_FAILURE);
74 NS_NAMED_LITERAL_STRING(INSERT_SQL,
75 "INSERT OR REPLACE INTO itunes_id_map (itunes_id, songbird_id) VALUES (?, ?)");
76 rv = mDBQuery->PrepareQuery(INSERT_SQL, getter_AddRefs(mInsertMapID));
77 NS_ENSURE_SUCCESS(rv, rv);
79 NS_NAMED_LITERAL_STRING(SELECT_SQL,
80 "SELECT songbird_id FROM itunes_id_map WHERE itunes_id = ?");
81 rv = mDBQuery->PrepareQuery(SELECT_SQL, getter_AddRefs(mSelectMapID));
82 NS_ENSURE_SUCCESS(rv, rv);
84 NS_NAMED_LITERAL_STRING(DELETE_SQL,
85 "DELETE FROM itunes_id_map WHERE songbird_id = ?");
87 rv = mDBQuery->PrepareQuery(SELECT_SQL, getter_AddRefs(mDeleteMapID));
88 NS_ENSURE_SUCCESS(rv, rv);
95 nsAString
const & aiTunesID,
96 nsAString
const & aSongbirdID) {
98 nsresult rv = mDBQuery->AddPreparedStatement(mInsertMapID);
99 NS_ENSURE_SUCCESS(rv, rv);
101 nsString compositeID(aiTunesLibID);
102 compositeID.Append(aiTunesID);
103 rv = mDBQuery->BindStringParameter(0, compositeID);
104 NS_ENSURE_SUCCESS(rv, rv);
106 rv = mDBQuery->BindStringParameter(1, aSongbirdID);
107 NS_ENSURE_SUCCESS(rv, rv);
110 rv = mDBQuery->Execute(&dbOK);
111 NS_ENSURE_SUCCESS(rv, rv);
112 NS_ENSURE_TRUE(dbOK == 0, NS_ERROR_FAILURE);
119 nsAString
const & aiTunesID,
120 nsAString & aSongbirdID) {
122 nsresult rv = mDBQuery->AddPreparedStatement(mSelectMapID);
123 NS_ENSURE_SUCCESS(rv, rv);
125 nsString iTunesID(aiTunesLibID);
126 iTunesID.Append(aiTunesID);
128 rv = mDBQuery->BindStringParameter(0, iTunesID);
129 NS_ENSURE_SUCCESS(rv, rv);
132 rv = mDBQuery->Execute(&dbOK);
133 NS_ENSURE_SUCCESS(rv, rv);
134 NS_ENSURE_TRUE(dbOK == 0, NS_ERROR_FAILURE);
136 nsCOMPtr<sbIDatabaseResult> result;
137 rv = mDBQuery->GetResultObject(getter_AddRefs(result));
138 NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
140 rv = result->GetRowCell(0, 0, aSongbirdID);
141 NS_ENSURE_SUCCESS(rv, rv);
149 nsresult rv = mDBQuery->AddPreparedStatement(mDeleteMapID);
150 NS_ENSURE_SUCCESS(rv, rv);
152 rv = mDBQuery->BindStringParameter(0, aSongbirdID);
153 NS_ENSURE_SUCCESS(rv, rv);
156 rv = mDBQuery->Execute(&dbOK);
157 NS_ENSURE_SUCCESS(rv, rv);
158 NS_ENSURE_TRUE(dbOK == 0, NS_ERROR_FAILURE);
nsresult RemoveSBIDEntry(nsAString const &aSongbirdID)
nsresult GetSBIDFromITID(nsAString const &aiTunesLibID, nsAString const &aiiTunesID, nsAString &aSongbirdID)
sbiTunesDatabaseServices()
~sbiTunesDatabaseServices()
nsresult MapID(nsAString const &aiTunesLibID, nsAString const &aiTunesID, nsAString const &aSongbirdID)
#define SB_DBQUERY_CONTRACTID