/* specific database table. */
/* */
/********************************************************/
-PUBLIC int sql_lock(SQLPTR *sqlptr,char *tablename)
+PUBLIC _Bool sql_lock(SQLPTR *sqlptr,char *tablename)
{
-return 1;
+#define OPEP "devsql.c:sql_lock,"
+
+_Bool locked;
+
+locked=false;
+if (sqlptr!=(SQLPTR *)0) {
+ SQLTYP *sql;
+
+ sql=(SQLTYP *)sqlptr;
+ switch(sql->sqldb) {
+ case db_postgres :
+ locked=pos_lock(sql->db.psql,tablename);
+ break;
+ case db_maria :
+ locked=mar_lock(sql->db.psql,tablename);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected db type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ }
+return locked;
+
+#undef OPEP
}
/*
\f
#define OPEP "devsql.c:sql_gettupple,"
SQLRES *rs;
-SQLTYP *sql;
-va_list args;
-char *cmd;
rs=(SQLRES *)0;
-sql=(SQLTYP *)sqlptr;
-va_start(args,fmt);
-if ((rou_vasprintf(&cmd,fmt,args))>0) {
- switch(sql->sqldb) {
- case db_postgres :
- rs=(SQLRES *)pos_gettupple(sql->db.psql,cmd);
- break;
- case db_maria :
- rs=(SQLRES *)mar_gettupple(sql->db.msql,cmd);
- break;
- default :
- (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
- OPEP,(int)sql->sqldb);
- break;
+if (sqlptr!=(SQLPTR *)0) {
+ SQLTYP *sql;
+ va_list args;
+ char *cmd;
+
+ sql=(SQLTYP *)sqlptr;
+ va_start(args,fmt);
+ if ((rou_vasprintf(&cmd,fmt,args))>0) {
+ switch(sql->sqldb) {
+ case db_postgres :
+ rs=(SQLRES *)pos_gettupple(sql->db.psql,cmd);
+ break;
+ case db_maria :
+ rs=(SQLRES *)mar_gettupple(sql->db.msql,cmd);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ (void) free(cmd);
}
- (void) free(cmd);
+ va_end(args);
}
-va_end(args);
return rs;
#undef OPEP
int numrow;
-numrow=0;
-SQLTYP *sql;
-sql=(SQLTYP *)sqlptr;
-switch(sql->sqldb) {
- case db_postgres :
- numrow=pos_nbrtupple((POSRES *)rs);
- break;
- case db_maria :
- numrow=mar_nbrtupple((MARRES *)rs);
- break;
- default :
- (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
- OPEP,(int)sql->sqldb);
- break;
+numrow=-1;
+if (sqlptr!=(SQLPTR *)0) {
+ SQLTYP *sql;
+
+ sql=(SQLTYP *)sqlptr;
+ switch(sql->sqldb) {
+ case db_postgres :
+ numrow=pos_nbrtupple((POSRES *)rs);
+ break;
+ case db_maria :
+ numrow=mar_nbrtupple((MARRES *)rs);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected db type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ numrow=0;
+ break;
+ }
}
return numrow;
PUBLIC _Bool sql_mngdata(SQLPTR *sqlptr,FLDTYP *field,SQLENUM action)
{
+(void) rou_alert(0,"JMPDBG sql_mngdata need to be implemented!");
return false;
}
-/*
-\f
-*/
-/********************************************************/
-/* */
-/* Procedure to lock access to a table. */
-/* */
-/********************************************************/
-PUBLIC _Bool sql_locktable(SQLPTR *sqlptr,char *tblname,_Bool action)
-
-{
-return action;
-}
extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
//procedure to LOCK access to a database table
-extern int sql_lock(SQLPTR *sqlptr,char *tablename);
+extern _Bool sql_lock(SQLPTR *sqlptr,char *tablename);
//procedure to UNLOCK access to a database table
extern int sql_unlock(SQLPTR *sqlptr,_Bool commit);
break;
case 1 : //record does not exist
done=false;
- if (sql_lock(sqlptr,RMTTBL)<0) {
+ if (sql_lock(sqlptr,RMTTBL)==false) {
(void) rou_alert(0,"%s Unable to dbd_lockhard %s table",OPEP,RMTTBL);
phase=999; //Unable to lock table
}
*/
/********************************************************/
/* */
+/* procedure to lock access to a specific table */
+/* within database. */
+/* */
+/********************************************************/
+PUBLIC _Bool mar_lock(MARPTR *maerptr,char *tablename)
+
+{
+#define OPEP "unimar.c:mar_lock,"
+
+_Bool locked;
+
+locked=false;
+#ifdef DB_MYSQL
+ {
+ (void) rou_alert(0,"%s not implemented yet",OPEP);
+ }
+#endif
+return locked;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* procedure to drop/free all result information */
/* */
/********************************************************/
//Procedure to detect and 'clean' any single quote within a string
extern char *mar_cleanquote(char *sequence);
+//locking database one table access
+extern _Bool mar_lock(MARPTR *marptr,char *tablename);
+
//procedure to drop/free all result information
extern MARRES *mar_dropresult(MARRES *rs);
*/
/********************************************************/
/* */
+/* procedure to lock access to a specific table */
+/* within database. */
+/* */
+/********************************************************/
+PUBLIC _Bool pos_lock(POSPTR *posptr,char *tablename)
+
+{
+#define OPEP "unipos.c:pos_lock,"
+
+_Bool locked;
+
+locked=false;
+#ifdef DB_POSTGRESQL
+ {
+ static const char *cmd="LOCK TABLE %s IN SHARE ROW EXCLUSIVE MODE";
+
+ PGconn *pf;
+ char fullcmd[300];
+ int phase;
+ _Bool proceed;
+
+ pf=(PGconn *)posptr;
+ (void) snprintf(fullcmd,sizeof(fullcmd),cmd,tablename);
+ phase=0;
+ proceed=true;
+ while (proceed==true) {
+ switch (phase) {
+ case 0 : //Starting lock
+ if (pos_request(posptr,"BEGIN")<0) {
+ (void) rou_alert(0,"%s Unable to BEGIN to lock table <%s>",
+ OPEP,tablename);
+ phase=999; //no need to go further
+ }
+ break;
+ case 1 : //lock table itself
+ if (pos_request(posptr,fullcmd)<0) {
+ (void) rou_alert(0,"%s Unable to lock table <%s>",
+ OPEP,tablename);
+ phase=999; //no need to go further
+ }
+ break;
+ case 2 : //lock done
+ locked=true;
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+ }
+#endif
+return locked;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* procedure to drop/free all result information */
/* */
/********************************************************/
//Procedure to detect and 'clean' any single quote within a string
extern char *pos_cleanquote(char *sequence);
+//locking database one table access
+extern _Bool pos_lock(POSPTR *marptr,char *tablename);
+
//procedure to drop/free all result information
extern POSRES *pos_dropresult(POSRES *rs);
//defining table about remote server
CREATE TABLE remotes (
+ remoteip TEXTUNIQUE, //remote IP number
lastscan DBTIMESTAMP //record laste update
DFLT NOW(),
lastupdate DBTIMESTAMP //record creation
DFLT NOW(),
- remoteip TEXTUNIQUE, //remote IP number
links INTEGER
DFLT 1, //how many time the remote connected
credit INTEGER //Remote IP current credit (-100..+100)