-
Notifications
You must be signed in to change notification settings - Fork 1
/
PMLSQLiteStatement.cs
104 lines (93 loc) · 3.04 KB
/
PMLSQLiteStatement.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Data.SQLite;
using Aveva.Core.PMLNet;
namespace PMLSQLite
{
/// <summary>
/// Represents a SQL statement to be executed.
/// </summary>
[PMLNetCallable()]
public class PMLSQLiteStatement
{
private SQLiteCommand cmd;
[PMLNetCallable()]
public PMLSQLiteStatement()
{
}
public PMLSQLiteStatement(SQLiteCommand c)
{
cmd = c;
}
[PMLNetCallable()]
public void Assign(PMLSQLiteStatement that)
{
if (cmd != null) cmd.Dispose();
cmd = that.cmd;
}
public override string ToString()
{
return cmd.CommandText;
}
/// <summary>
/// Binds a parameter to the specified placeholder name.
/// </summary>
/// <param name="param">Placeholder name</param>
/// <param name="value">Value to bind to the placeholder</param>
/// <returns>This instance itself</returns>
[PMLNetCallable()]
public PMLSQLiteStatement Bind(string param, string value)
{
cmd.Parameters.AddWithValue(param, value);
return this;
}
/// <summary>
/// Binds a value to the specified placeholder name.
/// </summary>
/// <param name="param">Placeholder name</param>
/// <param name="value">Value to bind</param>
/// <returns>This instance itself</returns>
[PMLNetCallable()]
public PMLSQLiteStatement Bind(string param, double value)
{
cmd.Parameters.AddWithValue(param, value);
return this;
}
/// <summary>
/// Binds a value to the specified placeholder name.
/// </summary>
/// <param name="param">Placeholder name</param>
/// <param name="value">Value to bind</param>
/// <returns>This instance itself</returns>
[PMLNetCallable()]
public PMLSQLiteStatement Bind(string param, bool value)
{
cmd.Parameters.AddWithValue(param, value);
return this;
}
/// <summary>
/// Executes the statement.
/// </summary>
[PMLNetCallable()]
public void Execute()
{
cmd.ExecuteNonQuery();
}
/// <summary>
/// Executes the statement and returns the first column of the first row.
/// </summary>
/// <returns>The first column of the first row</returns>
[PMLNetCallable()]
public string QueryOne()
{
return cmd.ExecuteScalar().ToString();
}
/// <summary>
/// Executes the statement and returns a new <see cref="PMLSQLiteResult"/> instance.
/// </summary>
/// <returns>A new <see cref="PMLSQLiteResult"/> instance</returns>
[PMLNetCallable()]
public PMLSQLiteResult Query()
{
return new PMLSQLiteResult(cmd.ExecuteReader());
}
}
}