All pastes #149671 Raw Edit

Macca

public c v1 · immutable
#149671 ·published 2006-08-26 00:41 UTC
rendered paste body
static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC){	pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;	char *id = NULL;	if (name == NULL) {		if (H->pgoid == InvalidOid) {			return NULL;		}		*len = spprintf(&id, 0, "%ld", (long) H->pgoid);	} else {		PGresult *res;		ExecStatusType status;#ifdef HAVE_PQEXECPARAMS		const char *q[1];		q[0] = name;		res = PQexecParams(H->server, "SELECT CURRVAL($1)", 1, NULL, q, NULL, NULL, 0);#else		char *name_escaped, *q;		size_t l = strlen(name);        		name_escaped = safe_emalloc(l, 2, 1);		PQescapeString(name_escaped, name, l);		spprintf(&q, 0, "SELECT CURRVAL('%s')", name_escaped);		res = PQexec(H->server, q);		efree(name_escaped); 		efree(q);#endif		status = PQresultStatus(res);		if (res && (status == PGRES_TUPLES_OK)) {			id = estrdup((char *)PQgetvalue(res, 0, 0));			*len = PQgetlength(res, 0, 0);		} else {			pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));		}		if (res) {			PQclear(res);		}	}	return id;}