#include "stdafx.h"


int oldTest(int argc, char** argv)
{
	int offset = 0;
	MySqlTools myTool;

	if (argc == 1)
	{
		offset = 0;
	}
	if (argc == 2)
	{
		sscanf(argv[1], "%d", &offset);
	}
	if (argc>2)
	{
		printf("usage: mysqlTools [offset_number]\n");
		return 0;
	}
	
	myTool.init("70.50.10.43");	
	myTool.saveToFile(29087);
	return 0;
}

void savePictureFromDB(TCHAR*  idStr)
{
	int id = 0;
	MySqlTools myTool;
	if (_stscanf(idStr, _T("%d"), &id)!= 0)
	{
		if (myTool.init("70.50.10.43"))
		{
			myTool.saveToFile(id);
		}
	}
}

void savePictureFromFile(TCHAR* fileName)
{
	LPBYTE ptr = NULL;
	MySqlTools myTool;	  
	DWORD  size = 0;
	if (myTool.init("70.50.10.43"))
	{
		if (mapFile(fileName, ptr, size))
		{
			myTool.doSaveToFile(ptr, size);
		}
	}
}

void remakePicture(TCHAR*  idStr)
{
	int id = 0;
	MySqlTools myTool;	
	if (_stscanf(idStr, _T("%d"), &id)!= 0)
	{  
		if (myTool.init("70.50.10.43"))
		{
			myTool.remakePicture(id);
		}
	}
}



int _tmain(int argc, TCHAR** argv)
{
	MySqlTools myTool;
	if (argc == 3)
	{ 		
		//savePictureFromFile(_T("original.jpg"));
		if (_tcsicmp(argv[1], _T("insert"))==0)
		{
			myTool.batchInsert(argv[2]);
		}
		else
		{
			if (_tcsicmp(argv[1], _T("remake"))==0)
			{  				
				remakePicture(argv[2]);
			}
			else
			{
				if (_tcsicmp(argv[1], _T("retrieve"))==0)
				{  				
					savePictureFromDB(argv[2]);
				}
			}
		}
	}
	else
	{
		_tprintf(_T("usage: mysqltools.exe [option] [param]\n"));		
	}	  
	return 0;
}