// SQLDatabase.cpp : Defines the entry point for the console application.

// fake functions just to make it compile
bool url2normal(const char* a, char *b, const char* c,int d){
	return true;
}
bool _downloadURL(const char* a, const char* b, const char* c, const char* d) {
	return true;
}
// --- end of faked functions

#include "stdio.h"
#include "stdlib.h"
#include "../RSSParser/SQLDatabase.h"

int main(int argc, char* argv[])
{


	//@TEST Only <----------------------------------------
	

	CSQLDataBase db;
	db.init("performance.db", &m_downloadDaemon);

	for (int j=0; j< 50; j++){
		db.execute("BEGIN;");
		for (int i=0; i<100; i++) {
			
			
			ItemInfo itemInfo;
			itemInfo.author = "william";
			itemInfo.cando = 0xF1;
			itemInfo.link = "http://test.org";
			itemInfo.status = 12;
			itemInfo.description = "This is the item test description";
			itemInfo.title = "itemInfo test";
			itemInfo.pubDate = "10/10/2008";
			itemInfo.downloadDate = NULL;
			itemInfo.length = 1459843332;
			itemInfo.thumbnailURL = "http://";			
			itemInfo.duration = i;
			char tmp[256];
			sprintf(tmp, "%s%d_%d", "test_", i, j);
			itemInfo.mediaURL = tmp;

			db.insertItem(&itemInfo);
		}

		db.execute("COMMIT;");

	}
	
	return false;


	//------------------------------------------------------



	CSQLDataBase database;

	if (!database.init("test.db", NULL)){
		printf("!!!! Cannot create SQL table\n");
	}


	// form channel info
	ChannelInfo channelInfo;

	channelInfo.author = "william";
	channelInfo.cando = 0xF1;
	channelInfo.link = "http://test.org0";
	channelInfo.status = 12;
	channelInfo.description = 0;
	channelInfo.title = "this2";
	channelInfo.pubDate = "10/20/2008";


	// form item info
	ItemInfo itemInfo;
	itemInfo.author = "william";
	itemInfo.cando = 0xF1;
	itemInfo.link = "http://test.org";
	itemInfo.status = 12;
	itemInfo.description = "This is the item test description";
	itemInfo.title = "itemInfo test";
	itemInfo.pubDate = "10/10/2008";
	itemInfo.downloadDate = NULL;
	itemInfo.length = 1459843332;
	itemInfo.duration = 356;
	itemInfo.mediaURL = "test good1";

	database.addToLibrary(&itemInfo, &channelInfo);


	Query q(database.getDB());
	q.get_result("select itemID, channelID, title,mediaURL from itemTable order by title");
	while (q.fetch_row())
	{
		long itemID = q.getval();
		const char *title = q.getstr();
		const char *mediaURL = q.getstr();
		printf("#%ld: %s %s\n", itemID, title, mediaURL);
	}
	q.free_result();


	q.get_result("select COUNT(*) from itemTable");
	while (q.fetch_row())
	{
		long count = q.getval();

		printf("Total %d items\n", count);
	}
	q.free_result();




	database.removeItemFromLibrary(4);

	database.removeChannelFromLibrary(2);

	database.subscribe(&channelInfo);

	database.unSubscribe(3);

	

	return 0;
}
