示例#1
0
int
initialize_db ()
{
    int rc = 1;
    struct stat buf;
    int i = 0;
    FILE *fp;

    fp = stdout;

    fprintf (fp, "Begun initialize_db\n");

    fprintf (fp, "1...Initializing database from path...%s\n", DATABASE);
    i = stat (DATABASE, &buf);
    fprintf (fp, "2...Initializing database...:%d\n", i);

    if ((i < 0) || (buf.st_size == 0))
    {
        fprintf (fp, "Initializing database...\n");
        rc = open_sqlite (DATABASE);
        if (rc == 0)
        {
            fprintf (fp, "Create database failure!\n");
        }
        close_sqlite ();
    }

    fprintf (fp, "Ended initialize_db\n");

    return rc;
}
示例#2
0
 void initialise_easy_sqlite_library() {
     printf("Actually going to initialise wish me luck!");
     if (initialised_easy_sqlite_library) return;
     open_sqlite("easy_sqlite_library.db");
     std::string table_name = "OpCodeCalls";
     std::string table_name_suffix = "";
     std::string schema = "";
     create_table(table_name, table_name_suffix, schema);
     create_easy_sqlite_tables();
     initialised_easy_sqlite_library=true;
 }
示例#3
0
char * read_sqlite_data(sqlite3 * pSqlite3, char *table, char *rcvbuf)
{
	int i;
	sqlite3 *db;
	sqlite3_stmt *stmt;
	char name[16], occ[16];
	
	char*sql_select="select * from people;";
	char*sql_select_machine="select * from machine;";
	
	//justify the input parameter 
	if ( NULL == pSqlite3 || NULL == table)
	{
 		printf("%s:%d Error input!\n",__FILE__,__LINE__);
		return 0;
	}

	printf("Show the sizeof rcvbuf %d\n",sizeof(rcvbuf));
	// 	memset(rcvbuf,0x00,sizeof(rcvbuf));
// 	if ( (db =open_sqlite("/mnt/hgfs/gtk_using/sqlite_mode/test_sqlite.db")) == NULL) 
	if ( (db =open_sqlite("/mnt/hgfs/gtk_using/tmp/server/test_sqlite.db")) == NULL) 
	{
		printf("sqlite open err(%s)", format_sqlite_err(db));
	}	
// 	sqlite3_prepare(db, sql_select, strlen(sql_select), &stmt, NULL);
	printf("hell-1\n");
	sqlite3_prepare(db, sql_select_machine, strlen(sql_select_machine), &stmt, NULL);
	i=0;
	printf("hell-2\n");
	while(SQLITE_DONE !=sqlite3_step(stmt))
	{
		printf("Result[%d]: macid=%s, time=%s, mac_order=%s\n",
			i++,
			sqlite3_column_text(stmt, 0),
			sqlite3_column_text(stmt, 1),
			sqlite3_column_text(stmt, 2)
			);
		memcpy(rcvbuf+strlen(rcvbuf),sqlite3_column_text(stmt, 0),strlen(sqlite3_column_text(stmt, 0)));
		memcpy(rcvbuf+strlen(rcvbuf),",",sizeof(","));
		memcpy(rcvbuf+strlen(rcvbuf),sqlite3_column_text(stmt, 1),strlen(sqlite3_column_text(stmt, 1)));
		memcpy(rcvbuf+strlen(rcvbuf),",",sizeof(","));
		memcpy(rcvbuf+strlen(rcvbuf),sqlite3_column_text(stmt, 2),strlen(sqlite3_column_text(stmt, 2)));
		memcpy(rcvbuf+strlen(rcvbuf),"  ",sizeof("  "));		
	}
	printf("hell-3  SQLITE_DONE:%d\n",SQLITE_DONE);	
	sqlite3_finalize(stmt);
	sqlite3_close(db);
	return 0;	
}
示例#4
0
// int sqlite_operation_add(void)
// {
// 		int i;
// 		sqlite3 *db;
// 		sqlite3_stmt *stmt;
// 		char name[16], occ[16];
// 		char*sql_drop="drop table if exists people;";
// 		char*sql_create="create table people (name, occupation);";
// 		char*sql_insert="insert into people values (?, ?);";
// 		char*sql_select="select * from people;";
// 		Tpeople inval = {"lwz","dev"};
// 
// 	if ( (db =open_sqlite("/mnt/hgfs/gtk_using/sqlite_mode/test_sqlite.db")) == NULL) 
// 	{
//   		printf("sqlite open err(%s)", format_sqlite_err(db));
// 	}
// 	printf("shwo the db:%d\n", db);
// // 	 execute_sql(db,sql_drop);
// 	 execute_sql(db,sql_create);
//      insert_sqlite_data(db,&inval);
// 
//      sqlite3_prepare(db, sql_select, strlen(sql_select), &stmt, NULL);
//      i=0;
//  while(SQLITE_DONE !=sqlite3_step(stmt))
// 	{
//          printf("Result[%d]: name=%s, occ=%s\n",
//              i++,
// 			sqlite3_column_text(stmt, 0),
// 			 sqlite3_column_text(stmt, 1));
// 	}
// 		
// 	sqlite3_finalize(stmt);
// 	sqlite3_close(db);
// 	return 0;
// }
int sqlite_operation_add(void)
{
	int i;
	sqlite3 *db;
	sqlite3_stmt *stmt;
	char name[16], occ[16];
	char*sql_drop="drop table if exists machine;";
	char*sql_create="create table machine (macid, time, mac_order);";//"create table people (name, occupation);";
	char*sql_insert="insert into machine values (?, ?, ?);";
 	char*sql_select="select * from machine;";
//	char*sql_select="select macid from machine limite 1;";
/*	Tpeople inval = {"lwz","dev"};*/
	
	if ( (db =open_sqlite("/mnt/hgfs/gtk_using/sqlite_mode/test_sqlite.db")) == NULL) 
	{
		printf("sqlite open err(%s)", format_sqlite_err(db));
	}
	printf("shwo the db:%d\n", db);
 // 	execute_sql(db,sql_drop);
	execute_sql(db,sql_create);
	insert_sqlite_data(db,&macval);
	
	sqlite3_prepare(db, sql_select, strlen(sql_select), &stmt, NULL);
	i=0;
	while(SQLITE_DONE !=sqlite3_step(stmt))
	{
		printf("Result[%d]: macid=%s, time=%s, mac_order=%s\n",
			i++,
			sqlite3_column_text(stmt, 0),
			sqlite3_column_text(stmt, 1),
			sqlite3_column_text(stmt, 2)
			);
// 		printf("Result[%d]: macid=%s\n",
// 			i++,
// 			sqlite3_column_text(stmt, 0)
// 			);
		sleep(1);
	}
	
	sqlite3_finalize(stmt);
	sqlite3_close(db);
	return 0;
}
示例#5
0
/***********************************************************************************************
                        MAIN MENU FOR RETAIL

***********************************************************************************************/
int
main (void)
{
    struct tm intim;
    int Ret_val;
    double amount;
    unsigned char str[100] = "";
    pthread_t syncT;
    pthread_attr_t attr;
    int newprio;
    struct sched_param param;
    int ret;


//fp = fopen (logFile, "w+");
    fp = stdout;

    fprintf(fp,"Begun main()");
    fflush(fp);

    lk_open ();
    prn_open ();
    mscr_open ();
    lk_dispinit ();

    lk_dispclr();

    strcpy(DATABASE,"/mnt/jffs2/fps.sqlite");

    initialize_db ();

    open_sqlite (DATABASE);

    strcpy(CONFIG_FILE, get_config("CONFIG_FILE",tmpbuf,"0"));	//Need OFFICE ID From config file before init_globals
    read_config (CONFIG_FILE);
    strcpy(OFFICE_ID,getVal("office_id")); // Get from config file
    strcpy(SESSION_ID,"");

    fprintf(fp,"office_id:",OFFICE_ID);
    fflush(fp);

    init_globals();

    strcpy(IP,getVal("remote_url"));
    strcpy(shop_id,getVal("shop"));
    strcpy(terminal,getVal("terminal"));
    strcpy(tempFile,"/mnt/jffs2/dat");
    strcpy(svr_username,getVal("server_user"));
    strcpy(svr_password,getVal("server_pwd"));

    setAuthType();

    if(strcmp(toUpper(getVal("show_splash")),"TRUE")==0)
    {
        lk_disptext (1, 0, "        PDS ", 1);
        lk_disptext (3, 0, "     Govt of AP", 0);
        lk_disptext (4, 0, "    Version:0.9", 0);
        lk_disptext (5, 0, "  Enter to continue", 0);
        lk_getkey ();
        lk_dispclr ();
    }

    if(strcmp(toUpper(getVal("commMode")),"ETHERNET") == 0)
        ip_setup ();

    strcpy(background,getVal("background"));

    pthread_attr_init(&attr);
    pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
    newprio = 1;
    param.sched_priority = newprio;
    pthread_attr_setschedparam(&attr,&param);

    if(strcmp(background,"true")==0) {
        fprintf(fp,"Starting a background thread");
        fflush(fp);

        if (pthread_create (&syncT, &attr, syncThread, NULL) != 0)
            fprintf (stderr, "Error creating the thread");
    }

    while(1) {
        ret = login();

        printFlag = FALSE;

        if(ret==USER)
            main_menu();
        else if(ret == ADMIN)
            admin_menu();
        else {
            lk_dispclr();
            lk_disptext (2, 0, "Invalid credentials", 0);
            lk_getkey ();
            lk_dispclr ();
        }
    }

    prn_close ();			// closing printer
    lk_close ();			// closing pinpad
    mscr_close ();		// closing magnetic swipe
    close_sqlite ();

    fprintf(fp,"Ended main()");
    fflush(fp);

    return SUCCESS;
}