Re: [gnome-db] Last insert feature request
- From: "Daniel Espinosa" <esodan gmail com>
- To: gnome-db-list gnome org
- Subject: Re: [gnome-db] Last insert feature request
- Date: Tue, 27 Nov 2007 19:21:26 -0600
I have modified a the current get_last_insert_id for PostgreSQL provider to:
static GdaParameter *
gda_postgres_provider_get_last_inserted_id (GdaServerProvider *provider,
GdaConnection *cnc,
GdaDataModel *recset)
{
Oid oid;
PGresult *pgres;
GdaPostgresConnectionData *priv_data;
GdaPostgresProvider *pg_prv = (GdaPostgresProvider *) provider;
g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pg_prv), NULL);
g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
if (!priv_data) {
gda_connection_add_event_string (cnc, _("Invalid PostgreSQL handle"));
return NULL;
}
if (recset) {
g_return_val_if_fail (GDA_IS_POSTGRES_RECORDSET (recset), NULL);
/* get the PQresult from the recordset */
pgres = gda_postgres_recordset_get_pgresult (GDA_POSTGRES_RECORDSET (recset));
if (pgres) {
oid = PQoidValue (pgres);
if (oid != InvalidOid)
{
GdaParameter *param;
GValue *value;
g_value_init (value, G_TYPE_INT);
g_value_set_int (value, oid);
gda_parameter_new (G_TYPE_INT);
gda_parameter_set_value (param, value);
return param;
}
}
return NULL;
}
/* get the last inserted OID kept */
if (priv_data->last_insert_id)
{
GdaParameter *param;
GValue *value;
GValue *str;
gint *oid;
g_value_init (str, G_TYPE_STRING);
g_value_set (str, priv_data->last_insert_id);
g_value_init (value, G_TYPE_INT);
g_value_transform (str, value);
gda_parameter_new (G_TYPE_INT);
gda_parameter_set_value (param, value);
return param;
}
else
return NULL;
}
2007/11/27, Daniel Espinosa <esodan gmail com>:
> For today gda_server_provider_get_last_insert_id () returns a gchar*,
> but what about to return a GdaParameter?
>
> If you return a GdaParameter the implementator will know the data type
> to return and will set the correct GType and GValue pair to the
> returned object.
>
> Then the developer could use this GdaParameter to find the a value in
> the database using a query like:
>
> SELECT * FROM ## /* name=parameter_name type = parameter_type */ = ##
> /* name=parameter_value type=parameter_type */
>
> This could help when the program insert values in the DB and needs to
> use it inmediately, and will avoid a DBMS specific hack for each one.
>
> Even could exist a
>
> GdaDataModel* gda_connection_get_last_inserted
>
> This function will use the GdaParameter returned by the
> gda_server_provider_get_last_insert_id function to return a
> GdaDataModel with just one row with the last inserted row in the DB.
>
> The new function could be called:
>
> GdaParameter* gda_server_provider_get_last_inserted_id
> (GdaServerProvider* provider)
>
> in order to avoid API break in the 3.x series.
>
> --
> Trabajar, la mejor arma para tu superación
> "de grano en grano, se hace la arena" (R) (entrámite, pero para los
> cuates: LIBRE)
>
--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los
cuates: LIBRE)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]