collect params of subqueries
[sqlgg.git] / demo / demo_csharp.cs
blobd6ceeaed0928d4352140097044aac83ce4e64dc6
1 using System;
2 using System.Data;
3 using MySql.Data.MySqlClient;
5 public class Test
7 public static void Main(string[] args)
9 string connectionString = "Server=localhost;Database=test;User ID=root;Password=;";
10 IDbConnection conn = new MySqlConnection(connectionString);
11 conn.Open();
13 sqlgg.all gen = new sqlgg.all(conn);
15 gen.drop_person.execute();
16 gen.drop_money.execute();
18 gen.create_person.execute();
19 gen.create_money.execute();
21 IDbCommand last_id = conn.CreateCommand();
22 last_id.CommandText = "SELECT LAST_INSERT_ID()";
23 last_id.Prepare();
25 gen.add_person.execute("John","Black");
26 long john = (long)last_id.ExecuteScalar();
28 gen.add_person.execute("Ivan","Petrov");
29 long ivan = (long)last_id.ExecuteScalar();
31 gen.add_person.execute("Sancho","Alvares");
32 long sancho = (long)last_id.ExecuteScalar();
34 // add money relations
35 gen.add_money.execute(john,ivan,200);
36 gen.add_money.execute(john,sancho,100);
37 gen.add_money.execute(john,sancho,250);
38 gen.add_money.execute(sancho,ivan,300);
40 Console.WriteLine("Total transfers:");
41 foreach (var row in gen.calc_total.rows())
43 Console.WriteLine(row.fullname + " = " + row.total);
46 Console.WriteLine("Donors:");
47 gen.list_donors.execute("petrov",100,delegate(string surname) { Console.WriteLine(surname); });
49 conn.Close();
50 conn = null;