Subversion Repositories mdb

Rev

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

Rev 25 Rev 29
Line 506... Line 506...
506
	/* Tell client which page to show */
506
	/* Tell client which page to show */
507
	sprintf(hv0, "PAGE:%s;FOLDERNAME:%s;", p_type, name);
507
	sprintf(hv0, "PAGE:%s;FOLDERNAME:%s;", p_type, name);
508
	write (s1, hv0, strlen (hv0));
508
	write (s1, hv0, strlen (hv0));
509
	
509
	
510
	/* Retrieve data from database */
510
	/* Retrieve data from database */
511
	line = 0;
511
	line = pos = 1;
512
	
512
	
513
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
513
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
514
	{
514
	{
515
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
515
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
516
		strcpy(query, "ERROR:LIST:Error preparing a SQL statement;");
516
		strcpy(query, "ERROR:LIST:Error preparing a SQL statement;");
Line 518... Line 518...
518
		return FALSE;
518
		return FALSE;
519
	}
519
	}
520
	
520
	
521
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
521
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
522
	{
522
	{
523
		line++;
523
		if (pos >= start && pos < (start + length))
524
		
524
		{
525
		if (line >= start && line < (start + length))
-
 
526
			listCallback(s1, p_type, line, res);
525
			listCallback(s1, p_type, line, res);
-
 
526
			line++;
-
 
527
		}
527
		
528
		
528
		if (line >= (start + length))
529
		if (pos >= (start + length))
529
			break;
530
			break;
-
 
531
		
-
 
532
		pos++;
530
	}
533
	}
531
	
534
	
532
	sqlite3_finalize(res);
535
	sqlite3_finalize(res);
533
	sqlite3_close(db);
536
	sqlite3_close(db);
534
	return TRUE;
537
	return TRUE;
Line 559... Line 562...
559
 */
562
 */
560
int listPlaylists(int s1, int start, int length)
563
int listPlaylists(int s1, int start, int length)
561
{
564
{
562
	USERS *act;
565
	USERS *act;
563
	char hv0[512], *user, *playlist;
566
	char hv0[512], *user, *playlist;
564
	int pos;
567
	int pos, line;
565
 
568
 
566
	if (userchain == NULL)
569
	if (userchain == NULL)
567
	{
570
	{
568
		strcpy(hv0, "ERROR:PLAYLIST:No user selected;");
571
		strcpy(hv0, "ERROR:PLAYLIST:No user selected;");
569
		write(s1, hv0, strlen(hv0));
572
		write(s1, hv0, strlen(hv0));
570
		return FALSE;
573
		return FALSE;
571
	}
574
	}
572
 
575
 
573
	act = userchain;
576
	act = userchain;
574
	pos = 1;
577
	pos = line = 1;
575
 
578
 
576
	while (act)
579
	while (act)
577
	{
580
	{
578
		if (pos < start)
581
		if (pos < start)
579
		{
582
		{
Line 584... Line 587...
584
		if (pos >= (start + length))
587
		if (pos >= (start + length))
585
			break;
588
			break;
586
 
589
 
587
		user = urlencode(act->uname);
590
		user = urlencode(act->uname);
588
		playlist = urlencode(act->playlist);
591
		playlist = urlencode(act->playlist);
589
		sprintf(hv0, "PLAYLIST:%d:%s:%s;", act->id, user, playlist);
592
		sprintf(hv0, "PLAYLIST:%d:%d:%s:%s;", line, act->id, user, playlist);
590
		write (s1, hv0, strlen(hv0));
593
		write (s1, hv0, strlen(hv0));
591
 
594
 
592
		if (user)
595
		if (user)
593
			free (user);
596
			free (user);
594
 
597
 
595
		if (playlist)
598
		if (playlist)
596
			free (playlist);
599
			free (playlist);
597
 
600
 
598
		act = act->next;
601
		act = act->next;
-
 
602
		line++;
599
	}
603
	}
600
 
604
 
601
	return TRUE;
605
	return TRUE;
602
}
606
}
603
 
607
 
Line 658... Line 662...
658
		strcpy(query, "ERROR:USER:Error opening database;");
662
		strcpy(query, "ERROR:USER:Error opening database;");
659
		write (s1, query, strlen(query));
663
		write (s1, query, strlen(query));
660
		return FALSE;
664
		return FALSE;
661
	}
665
	}
662
 
666
 
663
	sprintf(query, "select count(*) from musicdb as a where (select musicid from playlists as b where a.id = b.musicid and b.userid = %d)", act->id);
667
	sprintf(query, "select count(*) from \"main\".\"playlists\" where userid = %d", act->id);
664
	
668
 
665
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
669
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
666
	{
670
	{
667
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
671
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
668
		strcpy(hv0, "ERROR:USER:Error preparing a SQL statement;");
672
		strcpy(hv0, "ERROR:USER:Error preparing a SQL statement;");
669
		write(s1, hv0, strlen(hv0));
673
		write(s1, hv0, strlen(hv0));