HOWTO for common tasks

Open a connection
Define a data source (DSN)
Build statements without using a parser
INSERT INTO customers (e, f, g) VALUES (##p1::string, 15, 'joe')
SELECT people.firstname AS person, people.lastname, "date" AS birthdate, age FROM people
SELECT c."date", name AS person FROM "select" AS c INNER JOIN orders USING (id)
UPDATE products set ref='A0E''FESP' WHERE id = 14
DELETE FROM items WHERE id = ##theid::int
SELECT myfunc (a, 5, 'Joe') FROM mytable
SELECT name FROM master WHERE id IN (SELECT id FROM subdata)
INSERT INTO customers (e, f, g) SELECT id, name, location FROM subdate
SELECT id, name FROM subdata1 UNION SELECT ident, lastname FROM subdata2
SELECT CASE tag WHEN 'Alpha' THEN 1 WHEN 'Bravo' THEN 2 WHEN 'Charlie' THEN 3 ELSE 0 END FROM data
SELECT product_id, name, sum (4 * 5 * price * 1.200000) FROM invoice_lines
SELECT id, name, adress, cntry_id, countries.name FROM customers INNER JOIN countries ON (countries.id = cntry_id)
Execute a SELECT command
Modify the result of a SELECT command
Execute an INSERT, UPDATE or DELETE command
Get the last inserted row
Execute a DDL command
Get information about a table's columns
Update the meta data about a table
Validate a DML statement
Control value's assignment to various objects
Add your own data to a GdaMetaStore

This section is a list of small HOWTOs to get started quickly for some specific tasks, without the need to read all the documentation: quickly get to the code and read the corresponding documentation for further details.

Open a connection

Opening a connection to a database creates a GdaConnection object which is required to execute commands. The connections' parameters (which are specific to each type of database) can be either specified when opening the connection, or be used to define a data source (DSN) and the DSN name is then specified to open the connection.

For example, opening a connection to a PostgreSQL database named "mydb" one could use the following code:

GdaConnection *connection;
connection = gda_connection_open_from_string ("PostgreSQL", "DB_NAME=mydb", 
                                              "USERNAME=martin;PASSWORD=luther",
                                              GDA_CONNECTION_OPTIONS_READ_ONLY, NULL);
if (!connection)
    g_print ("CONNECTION FAILED\n");
else {
    /* use the opened connection */

    /* close the connection (assuming it's not used by another object) */
    g_object_unref (connection);
}