forked from JackTheMico/ObjectiveSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (87 loc) · 3.56 KB
/
Copy pathProgram.cs
File metadata and controls
100 lines (87 loc) · 3.56 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
namespace ObjectiveSQL
{
class Program
{
static void Main(string[] args)
{
testSelect();
testUpdate();
testInsert();
testDelete();
try
{
testInsertWhere();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
static void testSelect()
{
string usernamePrefix = "JOHN";
string role = "admin";
string username = "admin";
Command command = SQL.SELECT("*").From("USERS")
.Where("USERNAME LIKE ?", usernamePrefix)
.And("(ROLE=?", role).Or("USERNAME=?)", username).toCommand();
Console.WriteLine(command.getStatement());
command = SQL.SELECT("*").From("USERS")
.Where("USERNAME LIKE ?", usernamePrefix)
.Append("AND (")
.Append(role != null, "ROLE = ?", role)
.Or("USERNAME = ?", username)
.Append(")").toCommand();
Console.WriteLine(command.getStatement());
role = null;
command = SQL.SELECT("COUNT(1), ROLE")
.From("USERS")
.Where(false, "REGISTER_TIME > sysdate - 1") // dismissed
.AndIfNotEmpty("ROLE = ?", role) // dismissed
.And("1=1")
.GroupBy("ROLE").toCommand();
Console.WriteLine(command.getStatement());
List<string> levels = new List<string>() { "1","2", "3" };
command = SQL.SELECT("*")
.From("USERS")
.Where("USER_LEVEL IN ?", levels).toCommand();
Console.WriteLine(command.getStatement());
}
static void testUpdate()
{
Command command = SQL.UPDATE("USER")
.Set("AGE", 3)
.Set(false, "NAME", "admin").Where("ID=?", 1).toCommand();
Console.WriteLine(command.getStatement());
}
static void testInsert()
{
Command command = SQL.INSERT("USER")
.Values("ID", 1)
.Values("USERNAME", "admin")
.Values("PASSWORD", "admin")
.Values("AGE", null).toCommand();
Console.WriteLine(command.getStatement());
Dictionary<string,object> test = new Dictionary<string,object>();
test["ID"] = 1;
test["ADMIN"] = "Jack";
test["PWD"] = "123456";
Command comText = SQL.INSERT("USER").Values(test).toCommand();
Console.WriteLine("Dictionary--" + comText.getStatement());
}
static void testInsertWhere()
{
Command command = SQL.INSERT("USER").Values("NAME", "admin").Where("").toCommand();
Console.WriteLine(command.getStatement());
}
static void testDelete()
{
Command command = SQL.DELETE("USER").Where("ID in ?", new List<string>() { "1", "2", "3", "4", "5" }).toCommand();
Console.WriteLine(command.getStatement());
}
}
}