-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestaHelperDAO.cs
82 lines (69 loc) · 2.15 KB
/
TestaHelperDAO.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using Util;
using Model;
public class TestaHelperDAO
{
public static void Main(string[] args)
{
Person person = new Person()
{
name = "Carlos Eduardo",
};
try
{
InsertTradicional(person);
InsertComHelper(person);
DeleteTradicional(person);
DeleteComHelper(person);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw new Exception(ex.Message);
}
}
private static void InsertTradicional(Person person)
{
using (MySqlConnection connection = new DBConnect().Connection)
{
string sql = "INSERT INTO people (name) VALUES ('" + person.name + "')";
using (MySqlCommand command = new MySqlCommand(sql, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}
}
private static void InsertComHelper(Person person)
{
HelperDAO<Person>.SqlBuilder sqlBuilder = delegate(HelperDAO<Person> helper)
{
return "INSERT INTO people (name) VALUES ('" + helper.data.name + "')";
};
new HelperDAO<Person>(person).Insert(sqlBuilder);
}
private static void DeleteTradicional(Person person)
{
using (MySqlConnection connection = new DBConnect().Connection)
{
string sql = "DELETE FROM people"; // Insecure!
using (MySqlCommand command = new MySqlCommand(sql, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}
}
private static void DeleteComHelper(Person person)
{
HelperDAO<Person>.SqlBuilder sqlBuilder = delegate(HelperDAO<Person> helper)
{
return "DELETE FROM people";
};
new HelperDAO<Person>(person).Delete(sqlBuilder, secureMode: false); // Optional argument defaults to true. Only allows insecure deletion explicitly.
}
}