Quick Start

This should be enough to get up and running with the library.

The following will show how to initialize a PgSqlGenerator, (PostgreSQL) do some queries and get some reports.

// initialize the PgSqlGenerator - takes in params or a connection string
var pg = new PgSqlGenerator("", 5432, "postgres", "sql", "testDB");

// output all of the table names in the 'testDB' database
foreach(string s in pg.TableNames) Console.WriteLine(s);

// get the first table from the list
table tbl = pg.GetTable(pg.TableNames.First());

// generate a random insert query for the table:
string insert = SqlGenerator.Insert.For(tbl);

// run the query
int rowsAffected = pg.RunNonQuery(insert);

/* that is the basics, the class can do a lot more
   next is the easiest and most useful stuff to use, fully automated */

// automatically generate a bulk insert of 100 records, execute it and return the results
QueryInformation info = pg.ExecuteBulkInsert(tbl, 100);
Console.WriteLine("SQL query ran: " + info.Query);
Console.WriteLine("records affected: " + info.Affected);
Console.WriteLine("execution time (milliseconds): " + info.Time);

Last edited Dec 2, 2010 at 1:43 PM by naspinski, version 3


No comments yet.