-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathRecordSetMySQL.ahk
109 lines (88 loc) · 1.88 KB
/
RecordSetMySQL.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
;namespace DBA
/*
Represents a result set of an MySQL Query
*/
class RecordSetMySQL extends DBA.RecordSet
{
_colNames := 0 ; Collection<ColumnNames>
_colCount := 0
_query := 0 ; ptr to Resultset/Query
_db := 0 ; ptr to DataBase
_eof := false ; bool
CurrentRow := 0 ; int - row number
__New(db, requestResult){
this._db := db
this._query := requestResult
if(this._query != 0){
this._colNames := this.getColumnNames()
this.MoveNext()
}
}
/*
Is this RecordSet valid?
*/
IsValid(){
return (this._query != 0)
}
/*
Returns an Array with all Column Names
*/
getColumnNames(){
mysqlFields := MySQL_fetch_fields(this._query)
colNames := new Collection()
i := 0
for each, mysqlField in mysqlFields
{
colNames.Add(mysqlField.Name())
i++
}
this._colCount := i
return colNames
}
getEOF(){
return this._eof
}
MoveNext() {
static EOR := -1
this.ErrorMsg := ""
this.ErrorCode := 0
this._currentRow := 0
if (!this._query) {
this.ErrorMsg := "Invalid query handle!"
this._eof := true
return false
}
rowptr := MySQL_fetch_row(this._query)
if (!rowptr){
; // we reached eof
this.ErrorMsg := "RecordSet is empty! (eof)"
this.ErrorCode := 1
this._eof := true
return false
}
lengths := MySQL_fetch_lengths(this._query)
datafields := new Collection()
Loop % this._colCount
{
length := GetUIntAtAddress(lengths, A_Index - 1)
fieldPointer := GetPtrAtAddress(rowptr, A_Index - 1)
fieldValue := StrGet(fieldPointer, length, "CP0")
datafields.Add(fieldValue)
}
this._currentRow := new DBA.Row(this._colNames, datafields)
this.CurrentRow++
return true
}
Reset() {
throw Exception("Not Supported!",-1)
}
Close() {
this.ErrorMsg := ""
this.ErrorCode := 0
if(this._query == 0)
return true
MySQL_free_result(this._query)
this._query := 0
return true
}
}