C/C++ code#include
#include
#include
#include
using namespace std;
int HourLevelFoilder = 1;
int Remove_Pic(char *removetarget)
{
if(remove(removetarget))
{
printf("\n");
printf("++++++++++++++++++++++++++++++++++++++++++++\n");
printf("Could not delete the file %s \n",removetarget);
printf("++++++++++++++++++++++++++++++++++++++++++++\n");
return 1;
}
else
{
printf("\n");
printf("++++++++++++++++++++++++++++++++++++++++++++\n");
printf("File delect %s\n",removetarget);
printf("++++++++++++++++++++++++++++++++++++++++++++\n");
return 0;
}
}
/*
// scaleplate 123456789012345678901234
// example jpg file name type 5555505-20120606140004-1
// common Format *******-YYYYMMDDhhmmss-*
// getdate 2012-05-30 11:15:26
// getintersectionnum 7777701
// getpiclastnum 1
*/
int Set_Remove_Info(char *getdate,char *getintersectionnum,char *getpiclastnum)
{
char trypath1[200];
char trypath2[200];
char filename1[200];
char filename2[200];
char target[200];
int watch = 99;
//get file name type 1 ,it looks like 5555505-20120606140004-1
memset(filename1,0,200);
strcpy(filename1,getintersectionnum); //7
strcat(filename1+7,"-"); //8 *******-
strncpy(filename1+8,getdate,4); //12 *******-YYYY
strncpy(filename1+12,getdate+5,2); //14 *******-YYYYMM
strncpy(filename1+14,getdate+8,2); //16 *******-YYYYMMDD
strncpy(filename1+16,getdate+11,2); //18 *******-YYYYMMDDhh
strncpy(filename1+18,getdate+14,2); //20 *******-YYYYMMDDhhmm
strncpy(filename1+20,getdate+17,2); //22 *******-YYYYMMDDhhmmss
strcat(filename1+22,"-"); //23 *******-YYYYMMDDhhmmss-
strcat(filename1,getpiclastnum); //24 *******-YYYYMMDDhhmmss-*
strcat(filename1,".jpg");
printf("filename = %s\n",filename1);
printf("example- = %s\n","5555505-20120606140004-1.jpg");
//get file name type 2,it looks like 5555505-20120606140004-1-i
memset(filename2,0,200);
strcpy(filename2,getintersectionnum); //7
strcat(filename2+7,"-"); //8 *******-
strncpy(filename2+8,getdate,4); //12 *******-YYYY
strncpy(filename2+12,getdate+5,2); //14 *******-YYYYMM
strncpy(filename2+14,getdate+8,2); //16 *******-YYYYMMDD
strncpy(filename2+16,getdate+11,2); //18 *******-YYYYMMDDhh
strncpy(filename2+18,getdate+14,2); //20 *******-YYYYMMDDhhmm
strncpy(filename2+20,getdate+17,2); //22 *******-YYYYMMDDhhmmss
strcat(filename2+22,"-"); //23 *******-YYYYMMDDhhmmss-
strcat(filename2,getpiclastnum); //24 *******-YYYYMMDDhhmmss-*
strcat(filename2+24,"-"); //23 *******-YYYYMMDDhhmmss-
strcat(filename2,getpiclastnum); //24 *******-YYYYMMDDhhmmss-*
strcat(filename2,".jpg");
printf("filename2 = %s\n",filename2);
printf("example is= %s\n","5555505-20120606140004-1-1.jpg");
for(int i=0;i<2;i++)
{
if(HourLevelFoilder == 1) // Folder has Hour level
{
// get path1
memset(trypath1,0,200);
strcpy(trypath1,"VHIPict/"); //tryPath1 = VHIPict/
strncpy(trypath1+8,getdate+8,2); //tryPath1 = VHIPict/DD
strcat(trypath1,"/"); //tryPath1 = VHIPict/DD/
printf("trypath1 = %s\n",trypath1);
//pathe connect with file name 1,generate target
memset(target,0,200);
strcpy(target,trypath1);
strcat(target,filename1);
printf("target in Lvfo[1] = %s\n",target);
if( Remove_Pic(target) ) //if remove success ,it will returns 0
{
printf("%s delect error\n",target);
watch = 0;
}
//path connect with file name 2,generate target
memset(target,0,200);
strcpy(target,trypath1);
strcat(target,filename2);
printf("target in Lvfo[1] = %s\n",target);
//如果 remoce失败 返回 1 watch也取反为真 则 2次删除都失败
if( Remove_Pic(target) || !watch ) //remove target and both failed
{
HourLevelFoilder = 0; //Set program to no HourLevelFoilder
continue;
}
return 0;
}
else //HourLevelFoilder has been set to 0
{
//reinit watch
watch = 99;
// get path2
memset(trypath2,0,200);
strcpy(trypath2,"VHIPict/");
strncpy(trypath2+8,getdate+8,2);
strcat(trypath2,"/");
strncpy(trypath2+11,getdate+11,2);
strcat(trypath2,"/");
printf("trypath2 = %s\n",trypath2);
//path2 connect with file name 1,generate target
memset(target,0,200);
strcpy(target,trypath2);
strcat(target,filename1);
printf("target in Lvfo[1] = %s\n",target);
if( Remove_Pic(target) )
{
printf("%s delect error\n",target);
watch = 0;
}
//path2 connect with file name 2,generate target
memset(target,0,200);
strcpy(target,trypath2);
strcat(target,filename2);
printf("target in Lvfo[1] = %s\n",target);
if( (!Remove_Pic(target)) || watch ) //remove target and both failed
{
return 1;
}
return 0;
}
}
}
int Get_Pic_Info(void)
{
sqlite3 *db;
sqlite3_stmt *stmt;
int rc;
int isdelectjpg = 0;
const char *tail;
char sqlstr[512];
char usbdbname[256]="epolice.db";
char *pathname="/storage/usb/";
char getdate[50];
char getintersectionnum[20];
char getpiclastnum[5];
memset(sqlstr,0,512);
sprintf(sqlstr,"select TGSJ,LKHM,WJKZM from PASSVEHICLE where CLSD > 200");
printf("%s\n",sqlstr);
rc = sqlite3_open(usbdbname, &db);
if( rc )
{
printf("Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 0;
}
rc = sqlite3_prepare(db, sqlstr, -1, &stmt, &tail);
if(rc != SQLITE_OK)
{
printf("SQL error: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 0;
}
rc = sqlite3_step(stmt);
while(rc==SQLITE_ROW) // if there is an another row ready,means this line is meaningful
{
memset(getdate,0,50);
sprintf(getdate,"%s",sqlite3_column_text(stmt,0)); //get date
printf("%s \n",getdate);
memset(getintersectionnum,0,20);
sprintf(getintersectionnum,"%s",sqlite3_column_text(stmt,1)); //get intersectionnum
printf("%s \n",getintersectionnum);
memset(getpiclastnum,0,5);
sprintf(getpiclastnum,"%s",sqlite3_column_text(stmt,2)); //get picture last number
printf("%s \n",getpiclastnum);
//remove the picture match these information
isdelectjpg = Set_Remove_Info(getdate,getintersectionnum,getpiclastnum);
if( isdelectjpg != 0 )
{
rc = sqlite3_prepare(db, sqlstr, -1, &stmt, &tail); //prepare sqlstr and stmt
if(rc != SQLITE_OK) //check prepare
{
printf("SQL error: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 0;
}
memset(sqlstr,0,512); //clean sqlstr
sprintf(sqlstr,"delete from PASSVEHICLE where TGSJ='%s'",getdate); //set sqlstr
printf("delect sql = %s\n",sqlstr);
rc = sqlite3_step(stmt); //execute sqlstr to delect date which speed>200
//reprepare sqlstr and stmt for selctect information form table
rc = sqlite3_prepare(db, sqlstr, -1, &stmt, &tail);
memset(sqlstr,0,512); //clean sqlstr
//prepare sqlstr,change sqlstr to select information
printf("%s\n",sqlstr);
sprintf(sqlstr,"select TGSJ,LKHM,WJKZM from PASSVEHICLE where CLSD > 200");
isdelectjpg = 0;
}
//select information form table
rc = sqlite3_step(stmt);
}
printf("Remove Finish\n");
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
}
int main(void)
{
Get_Pic_Info();
return 0;
}