forked from Mirrors/freeswitch
MODLANG-10 Modify Javascript exec function to return number of changed rows, thanks Dale.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4921 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
12c47bf96f
commit
50b5fe43a2
@ -457,6 +457,11 @@ SWITCH_DECLARE(void) switch_core_db_free_table(char **result);
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_core_db_free(char *z);
|
||||
|
||||
/**
|
||||
* Call this routine to find the number of rows changed by the last statement.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db);
|
||||
|
||||
/** Return values for switch_core_db_exec() and switch_core_db_step()*/
|
||||
#define SWITCH_CORE_DB_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
|
@ -117,7 +117,7 @@ static int db_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
struct db_obj *dbo = JS_GetPrivate(cx, obj);
|
||||
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
|
||||
*rval = INT_TO_JSVAL(0);
|
||||
|
||||
if (argc > 0) {
|
||||
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
@ -137,7 +137,11 @@ static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
|
||||
if (err) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
|
||||
switch_core_db_free(err);
|
||||
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
|
||||
*rval = INT_TO_JSVAL(-1);
|
||||
} else {
|
||||
int count = switch_core_db_changes(dbo->db);
|
||||
|
||||
*rval = INT_TO_JSVAL(count);
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
|
@ -142,6 +142,10 @@ SWITCH_DECLARE(void) switch_core_db_free(char *z)
|
||||
sqlite3_free(z);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db) {
|
||||
return sqlite3_changes(db);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
Loading…
Reference in New Issue
Block a user