-
Notifications
You must be signed in to change notification settings - Fork 72
/
RecordSetADO.ahk
120 lines (96 loc) · 1.91 KB
/
RecordSetADO.ahk
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
119
;namespace DBA
/*
Represents a result set of ADO
http://www.w3schools.com/ado/ado_ref_recordset.asp
*/
class RecordSetADO extends DBA.RecordSet
{
_adoRS := 0 ; ado recordset
__New(sql, adoConnection, editable = false){
this._adoRS := ComObjCreate("ADODB.Recordset")
if(editable)
this._adoRS.Open(sql, adoConnection, ADO.CursorType.adOpenKeyset, ADO.LockType.adLockOptimistic, ADO.CommandType.adCmdTable)
else
this._adoRS.Open(sql, adoConnection)
}
/*
Is this RecordSet valid?
*/
IsValid(){
return (IsObject(this._adoRS))
}
/*
Returns an Array with all Column Names
*/
getColumnNames(){
colNames := new Collection()
for adoField in this._adoRS.Fields
colNames.add(adoField.Name)
return colNames
}
getEOF(){
return this._adoRS.EOF
}
AddNew(){
if(this.IsValid())
{
this._adoRS.AddNew()
}
}
MoveNext() {
if(this.IsValid())
{
this._adoRS.MoveNext()
}
}
Delete(){
if(this.IsValid() && !this.getEOF())
{
this._adoRS.Delete(ADO.AffectEnum.adAffectCurrent)
}
}
Update(){
if(this.IsValid() && !this.getEOF())
{
this._adoRS.Update()
}
}
Reset() {
if(this.IsValid()){
this._adoRS.MoveFirst()
}
}
Count(){
cnt := 0
if(this.IsValid())
cnt := this._adoRS.RecordCount
return cnt
}
Close() {
if(this.IsValid())
{
this._adoRS.Close()
this._adoRS := null
}
}
__Get(propertyName){
if(IsObject(propertyName)){
throw Exception("Expected Index or Column Name!",-1)
}
if(propertyName = "EOF")
return this.getEOF()
if(!IsObjectMember(this, propertyName) && propertyName != "_currentRow"){
if(this.IsValid())
{
/*
* Param can either be the column index
* Or the column name
*/
if propertyName is Integer
propertyName-- ; ado zero based indexes
df := this._adoRS.Fields[propertyName] ; ADO uses zero based indexes
return df.Value
}
}
}
}