Subversion Repositories mdb

Rev

Rev 8 | Rev 12 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 9
Line 44... Line 44...
44
	char *zErrMsg = 0;
44
	char *zErrMsg = 0;
45
	int rc, id;
45
	int rc, id;
46
	sqlite3_stmt *res;
46
	sqlite3_stmt *res;
47
 
47
 
48
	strcpy(fname, configs.home);
48
	strcpy(fname, configs.home);
49
	strcat(fname, "/music.db");
49
	strcat(fname, MUSICDB);
50
 
50
 
51
	rc = sqlite3_open(fname, &db);
51
	rc = sqlite3_open(fname, &db);
52
 
52
 
53
	if (rc)
53
	if (rc)
54
	{
54
	{
Line 141... Line 141...
141
	}
141
	}
142
 
142
 
143
	userchain = NULL;
143
	userchain = NULL;
144
}
144
}
145
 
145
 
146
int selectUser (int s1, char *user)
146
int selectUser (int s1, const char *user)
147
{
147
{
148
	char query[1024];
148
	char query[1024];
149
	char fname[256];
149
	char fname[256];
150
	sqlite3 *db;
150
	sqlite3 *db;
151
	char *uname, *playlist, *zErrMsg = 0;
151
	char *uname, *playlist, *zErrMsg = 0;
152
	int rc, id, total;
152
	int rc, id, total;
153
	sqlite3_stmt *res;
153
	sqlite3_stmt *res;
154
	
154
	
155
	strcpy(fname, configs.home);
155
	strcpy(fname, configs.home);
156
	strcat(fname, "/music.db");
156
	strcat(fname, MUSICDB);
157
	
157
	
158
	rc = sqlite3_open(fname, &db);
158
	rc = sqlite3_open(fname, &db);
159
	
159
	
160
	if (rc)
160
	if (rc)
161
	{
161
	{
Line 174... Line 174...
174
		strcpy(query, "ERROR:USER:Error preparing a SQL statement;");
174
		strcpy(query, "ERROR:USER:Error preparing a SQL statement;");
175
		write(s1, query, strlen(query));
175
		write(s1, query, strlen(query));
176
		return FALSE;
176
		return FALSE;
177
	}
177
	}
178
 
178
 
179
	total = 0;
179
	total = sqlite3_column_count(res);
-
 
180
	sprintf(query, "USER:%s;TOTAL:%d;", user, total);
-
 
181
	write(s1, query, strlen(query));
180
 
182
	
181
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
183
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
182
	{
184
	{
183
		USERS *act;
185
		USERS *act;
184
 
186
 
185
		if ((act = addUser()) == NULL)
187
		if ((act = addUser()) == NULL)
Line 187... Line 189...
187
			sqlite3_finalize(res);
189
			sqlite3_finalize(res);
188
			sqlite3_close(db);
190
			sqlite3_close(db);
189
			return FALSE;
191
			return FALSE;
190
		}
192
		}
191
 
193
 
192
		total++;
-
 
193
		act->id = sqlite3_column_int(res, 0);
194
		act->id = sqlite3_column_int(res, 0);
194
		strncpy(act->uname, (const char *)sqlite3_column_text(res, 1), sizeof(act->uname));
195
		strncpy(act->uname, (const char *)sqlite3_column_text(res, 1), sizeof(act->uname));
195
		strncpy(act->playlist, (const char *)sqlite3_column_text(res, 2), sizeof(act->playlist));
196
		strncpy(act->playlist, (const char *)sqlite3_column_text(res, 2), sizeof(act->playlist));
196
	}
197
	}
197
 
198
 
198
	sqlite3_finalize(res);
199
	sqlite3_finalize(res);
199
	sqlite3_close(db);
200
	sqlite3_close(db);
200
 
201
 
201
	sprintf(query, "PTOTAL:%s:%d;", user, total);
-
 
202
	write(s1, query, strlen(query));
-
 
203
	return TRUE;
202
	return TRUE;
204
}
203
}
205
 
204
 
206
USERS *findPlaylist(char *playlist)
205
USERS *findPlaylist(char *playlist)
207
{
206
{