Browse code

- Support for raw sql queries

Jan Janak authored on 05/04/2007 13:26:10
Showing 3 changed files
... ...
@@ -466,6 +466,19 @@ int my_cmd_read(db_res_t* res, db_cmd_t* cmd)
466 466
 }
467 467
 
468 468
 
469
+int my_cmd_sql(db_res_t* res, db_cmd_t* cmd)
470
+{
471
+	struct my_cmd* mcmd;
472
+   
473
+	mcmd = DB_GET_PAYLOAD(cmd);
474
+	if (mysql_stmt_execute(mcmd->st)) {
475
+		ERR("Error while executing query: %s\n", mysql_stmt_error(mcmd->st));
476
+		return -1;
477
+	}
478
+	return 0;
479
+}
480
+
481
+
469 482
 static int bind_params(MYSQL_STMT* st, db_fld_t* fld)
470 483
 {
471 484
 	int i, n;
... ...
@@ -712,6 +725,17 @@ int my_cmd(db_cmd_t* cmd)
712 725
 		}
713 726
 		if (bind_result(res->st, cmd->result) < 0) goto error;
714 727
 		break;
728
+
729
+	case DB_SQL:
730
+		if (mysql_stmt_prepare(res->st, cmd->table.s, cmd->table.len)) {
731
+			ERR("Error while preparing raw SQL query: %s\n",
732
+				mysql_stmt_error(res->st));
733
+			goto error;
734
+		}
735
+		if (!DB_FLD_EMPTY(cmd->result)) {
736
+			if (bind_result(res->st, cmd->result) < 0) goto error;
737
+		}
738
+		break;
715 739
 	}
716 740
 
717 741
 	DB_SET_PAYLOAD(cmd, res);
... ...
@@ -48,6 +48,9 @@ int my_cmd_read(db_res_t* res, db_cmd_t* cmd);
48 48
 /* Runtime execution function for DB_PUT and DB_DEL */
49 49
 int my_cmd_write(db_res_t* res, db_cmd_t* cmd);
50 50
 
51
+/* Raw SQL query */
52
+int my_cmd_sql(db_res_t* res, db_cmd_t* cmd);
53
+
51 54
 int my_cmd_first(db_res_t* res);
52 55
 
53 56
 int my_cmd_next(db_res_t* res);
... ...
@@ -61,6 +61,7 @@ static cmd_export_t cmds[] = {
61 61
 	{"db_put",         (cmd_function)my_cmd_write, 0, 0, 0},
62 62
 	{"db_del",         (cmd_function)my_cmd_write, 0, 0, 0},
63 63
 	{"db_get",         (cmd_function)my_cmd_read, 0, 0, 0},
64
+	{"db_sql",         (cmd_function)my_cmd_sql, 0, 0, 0},
64 65
 	{"db_res",         (cmd_function)my_res,  0, 0, 0},
65 66
 	{"db_fld",         (cmd_function)my_fld,  0, 0, 0},
66 67
 	{"db_first",       (cmd_function)my_cmd_next, 0, 0, 0},