/
SQLInsertFromSelect.cs
118 lines (105 loc) · 2.62 KB
/
SQLInsertFromSelect.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ___________________________________________________
//
// © Hi-Integrity Systems 2008. All rights reserved.
// www.hisystems.com.au - Toby Wicks
// ___________________________________________________
//
using System.Collections;
using System;
using System.Data;
namespace DatabaseObjects.SQL
{
/// <summary>
/// Allows data to be inserted using records from another table.
/// </summary>
///
/// <example>
/// Dim objCopy As New DatabaseObjects.SQL.SQLInsertFromSelect
/// objCopy.Fields.Add("DestinationField1")
/// objCopy.Fields.Add("DestinationField1")
/// objCopy.TableName = "DestinationTable"
/// objCopy.Source.Fields.Add("SourceField1")
/// objCopy.Source.Fields.Add("SourceField1")
/// objCopy.Source.Tables.Add("SourceTable")
/// objCopy.Source.Where.Add("Field1", DatabaseObjects.SQL.ComparisonOperator.EqualTo, "ABC")
///
/// INSERT INTO DestinationTable
/// SELECT * FROM SourceTable
/// WHERE SomeField = Condition
/// or
/// INSERT INTO DestinationTable (IntoField1, IntoField2)
/// SELECT (FromField1, FromField2) FROM SourceTable
/// WHERE SomeField = Condition
///
/// </example>
/// <remarks></remarks>
public class SQLInsertFromSelect : SQLStatement
{
public class FieldsClass : System.Collections.Specialized.StringCollection
{
}
private string pstrInsertIntoTableName = string.Empty;
private FieldsClass pobjInsertIntoFields = new FieldsClass();
private SQLSelect pobjSourceSelect = new SQLSelect();
public SQLInsertFromSelect()
{
}
/// <summary>
/// Sets/Returns the fields that will be inserted into the database.
/// The order of the fields must match with the order of the fields from
/// the source SELECT statement.
/// </summary>
public FieldsClass Fields
{
get
{
return pobjInsertIntoFields;
}
set
{
if (value == null)
throw new NullReferenceException();
pobjInsertIntoFields = value;
}
}
/// <summary>
/// The table to insert into.
/// </summary>
public string TableName
{
get
{
return pstrInsertIntoTableName;
}
set
{
pstrInsertIntoTableName = value;
}
}
/// <summary>
/// The SELECT statement where the data is to be copied from.
/// The order of the fields must match the order of fields
/// specified in the Fields property.
/// </summary>
public SQLSelect Source
{
get
{
return pobjSourceSelect;
}
set
{
if (value == null)
throw new ArgumentNullException();
pobjSourceSelect = value;
}
}
public override string SQL
{
get
{
return base.Serializer.SerializeInsertFromSelect(this);
}
}
}
}