// DO NOT EDIT MANUALLY
//
// generated by sqlgg 0.2.3-43-g8cd5b20 on 2009-11-07T13:43Z
using System;
using System.Data;
using System.Collections.Generic;
namespace sqlgg
{
public class create_person
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "CREATE TABLE IF NOT EXISTS person (id INTEGER PRIMARY KEY AUTO_INCREMENT,name TEXT,surname TEXT)";
public create_person(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute()
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
return _cmd.ExecuteNonQuery();
}
} // public class create_person
public class add_person
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "INSERT INTO person (name,surname) VALUES (@name,@surname)";
public add_person(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute(String name, String surname)
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
IDbDataParameter param_0 = _cmd.CreateParameter();
param_0.ParameterName = "@name";
param_0.DbType = DbType.String;
_cmd.Parameters.Add(param_0);
IDbDataParameter param_1 = _cmd.CreateParameter();
param_1.ParameterName = "@surname";
param_1.DbType = DbType.String;
_cmd.Parameters.Add(param_1);
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
((IDbDataParameter)_cmd.Parameters[0]).Value = name;
((IDbDataParameter)_cmd.Parameters[1]).Value = surname;
return _cmd.ExecuteNonQuery();
}
} // public class add_person
public class create_money
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "CREATE TABLE IF NOT EXISTS money (src INTEGER, dst INTEGER, amount INTEGER)";
public create_money(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute()
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
return _cmd.ExecuteNonQuery();
}
} // public class create_money
public class add_money
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "INSERT INTO money VALUES (@src,@dst,@amount)";
public add_money(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute(Int64 src, Int64 dst, Int64 amount)
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
IDbDataParameter param_0 = _cmd.CreateParameter();
param_0.ParameterName = "@src";
param_0.DbType = DbType.Int64;
_cmd.Parameters.Add(param_0);
IDbDataParameter param_1 = _cmd.CreateParameter();
param_1.ParameterName = "@dst";
param_1.DbType = DbType.Int64;
_cmd.Parameters.Add(param_1);
IDbDataParameter param_2 = _cmd.CreateParameter();
param_2.ParameterName = "@amount";
param_2.DbType = DbType.Int64;
_cmd.Parameters.Add(param_2);
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
((IDbDataParameter)_cmd.Parameters[0]).Value = src;
((IDbDataParameter)_cmd.Parameters[1]).Value = dst;
((IDbDataParameter)_cmd.Parameters[2]).Value = amount;
return _cmd.ExecuteNonQuery();
}
} // public class add_money
public class calc_total
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "SELECT CONCAT(name,' ',surname) AS fullname, SUM(amount) as total FROM person JOIN money ON src = id GROUP BY id";
public calc_total(IDbConnection db)
{
_cmd = null;
_conn = db;
}
public delegate void callback(String fullname, Int64 total);
/**
execute query
String fullname, Int64 total
*/
public IEnumerable execute_reader()
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
IDataReader reader = _cmd.ExecuteReader();
while (reader.Read())
{
yield return reader;
}
reader.Close();
}
public int execute(callback result)
{
int count = 0;
foreach (var reader in execute_reader())
{
result(reader.GetString(0), reader.GetInt64(1));
count++;
}
return count;
}
public class row
{
public readonly String fullname;
public readonly Int64 total;
public row(IDataReader reader)
{
fullname = reader.GetString(0);
total = reader.GetInt64(1);
}
} // public class row
public IEnumerable rows()
{
foreach (var reader in execute_reader())
{
yield return new row(reader);
}
}
} // public class calc_total
public class list_donors
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "SELECT DISTINCT surname FROM person JOIN money ON src = id AND dst = (SELECT id FROM person WHERE surname LIKE @_0) LIMIT @limit";
public list_donors(IDbConnection db)
{
_cmd = null;
_conn = db;
}
public delegate void callback(String surname);
/**
execute query
String surname
*/
public IEnumerable execute_reader(String _0, Int64 limit)
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
IDbDataParameter param_0 = _cmd.CreateParameter();
param_0.ParameterName = "@_0";
param_0.DbType = DbType.String;
_cmd.Parameters.Add(param_0);
IDbDataParameter param_1 = _cmd.CreateParameter();
param_1.ParameterName = "@limit";
param_1.DbType = DbType.Int64;
_cmd.Parameters.Add(param_1);
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
((IDbDataParameter)_cmd.Parameters[0]).Value = _0;
((IDbDataParameter)_cmd.Parameters[1]).Value = limit;
IDataReader reader = _cmd.ExecuteReader();
while (reader.Read())
{
yield return reader;
}
reader.Close();
}
public int execute(String _0, Int64 limit, callback result)
{
int count = 0;
foreach (var reader in execute_reader(_0, limit))
{
result(reader.GetString(0));
count++;
}
return count;
}
public IEnumerable rows(String _0, Int64 limit)
{
foreach (var reader in execute_reader(_0, limit))
{
yield return reader.GetString(0);
}
}
} // public class list_donors
public class drop_person
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "DROP TABLE IF EXISTS person";
public drop_person(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute()
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
return _cmd.ExecuteNonQuery();
}
} // public class drop_person
public class drop_money
{
IDbCommand _cmd;
IDbConnection _conn;
public int? CommandTimeout;
static string sql = "DROP TABLE IF EXISTS money";
public drop_money(IDbConnection db)
{
_cmd = null;
_conn = db;
}
/**
execute query
*/
public int execute()
{
if (null == _cmd)
{
_cmd = _conn.CreateCommand();
_cmd.CommandText = sql;
_cmd.Prepare();
}
if (null != CommandTimeout) _cmd.CommandTimeout = CommandTimeout.Value;
return _cmd.ExecuteNonQuery();
}
} // public class drop_money
public class all
{
public readonly IDbConnection db;
public create_person create_person;
public add_person add_person;
public create_money create_money;
public add_money add_money;
public calc_total calc_total;
public list_donors list_donors;
public drop_person drop_person;
public drop_money drop_money;
public all(IDbConnection db)
{
this.db = db;
create_person = new create_person(db);
add_person = new add_person(db);
create_money = new create_money(db);
add_money = new add_money(db);
calc_total = new calc_total(db);
list_donors = new list_donors(db);
drop_person = new drop_person(db);
drop_money = new drop_money(db);
}
} // public class all
} // namespace sqlgg