Continued work on db function, db_init, db_start, db_ping ...
FossilOrigin-Name: 7cbcfcdc5f14785523f8b840277393efcf373fdbeabe91f348c8789dc9a3d0fe
This commit is contained in:
		
							
								
								
									
										38
									
								
								src/ac/db.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								src/ac/db.c
									
									
									
									
									
								
							@ -3,11 +3,13 @@
 | 
			
		||||
 | 
			
		||||
#include "cw_log.h"
 | 
			
		||||
 | 
			
		||||
#include "conf.h"
 | 
			
		||||
 | 
			
		||||
static sqlite3 *handle;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const char * init_tables = "\
 | 
			
		||||
	CREATE TABLE IF NOT EXISTS acs (acid TEXT PRIMARY KEY, TIMESTAMP lastseen); \
 | 
			
		||||
	CREATE TABLE IF NOT EXISTS acs (acid TEXT PRIMARY KEY, acname TEXT, lastseen TIMESTAMP); \
 | 
			
		||||
	CREATE TABLE IF NOT EXISTS acips (acid TEXT,ip TEXT); \
 | 
			
		||||
	";
 | 
			
		||||
 | 
			
		||||
@ -37,17 +39,45 @@ int db_init()
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static sqlite3_stmt * ping_stmt;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int db_start()
 | 
			
		||||
{
 | 
			
		||||
	const char * cmd = "REPLACE INTO acs ";
 | 
			
		||||
	sqlite3_stmt *stmt;
 | 
			
		||||
	int rc = sqlite3_prepare_v2(handle, "INSERT INTO acs (acid,acname) VALUES (?,?);",-1,&stmt,0);
 | 
			
		||||
	printf ("RC = %d %p\n",rc,stmt);
 | 
			
		||||
 | 
			
		||||
	rc = sqlite3_bind_text(stmt,1,conf_acid,-1,SQLITE_STATIC);
 | 
			
		||||
 | 
			
		||||
	printf ("RC: %d\n",rc);
 | 
			
		||||
 | 
			
		||||
	sqlite3_bind_text(stmt,2,conf_acname,-1,SQLITE_STATIC);
 | 
			
		||||
	sqlite3_step(stmt);
 | 
			
		||||
 | 
			
		||||
	rc = sqlite3_prepare_v2(handle, "UPDATE acs SET lastseen=datetime('now') WHERE acid=?;",-1,&ping_stmt,0);
 | 
			
		||||
	rc = sqlite3_bind_text(ping_stmt,1,conf_acid,-1,SQLITE_STATIC);
 | 
			
		||||
 | 
			
		||||
//	rc = sqlite3_prepare_v2(handle, "UPDATE acs SET lastseen=99 WHERE acid=? ;",-1,&ping_stmt,0);
 | 
			
		||||
	printf("RCPin: %d\n",rc);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
#include "conf.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int db_ping()
 | 
			
		||||
{
 | 
			
		||||
	int rc = sqlite3_step(ping_stmt);
 | 
			
		||||
 | 
			
		||||
	printf("Pingger\n");
 | 
			
		||||
	const char * cmd = "UPDATE acs SET lastseen=datetime('now') WHERE acid='%s'";
 | 
			
		||||
	printf(cmd,conf_acid);
 | 
			
		||||
 | 
			
		||||
	//int rc = sqlite3_prepare_v2(handle,cmd,-1,&ping_stmt,0);
 | 
			
		||||
	////printf ("Prepare rc: %d\n",rc);
 | 
			
		||||
 | 
			
		||||
	//printf(cmd,conf_acid);
 | 
			
		||||
	printf("\n");
 | 
			
		||||
 | 
			
		||||
//	int rc = sqlite3_exec(
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user