~ubuntu-branches/ubuntu/oneiric/haxe/oneiric

« back to all changes in this revision

Viewing changes to haxe/std/php/db/Mysql.hx

  • Committer: Bazaar Package Importer
  • Author(s): Jens Peter Secher
  • Date: 2010-01-31 23:08:43 UTC
  • mfrom: (5.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100131230843-1cxte2x20ypk9c25
Tags: 1:2.5-1
New upstream version, taken from new upstream subversion repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                var h = untyped __call__("mysql_query", s, c);
44
44
                if(untyped __physeq__(h, false))
45
45
                        throw "Error while executing "+s+" ("+untyped __call__("mysql_error", c)+")";
46
 
                return new MysqlResultSet(cast h);
 
46
                return new MysqlResultSet(cast h, cast c);
47
47
        }
48
48
 
49
49
        public function escape( s : String ) {
54
54
                return "'" + untyped __call__("mysql_real_escape_string", s, c) + "'";
55
55
        }
56
56
 
 
57
        public function addValue( s : StringBuf, v : Dynamic ) {
 
58
                if( untyped __call__("is_int", v) || __call__("is_null", v))
 
59
                        s.add(v);
 
60
                else if( untyped __call__("is_bool", v) )
 
61
                        s.add(if( v ) 1 else 0);
 
62
                else
 
63
                        s.add(quote(Std.string(v)));
 
64
        }
 
65
 
57
66
        public function lastInsertId() {
58
67
                return untyped __call__("mysql_insert_id", c);
59
68
        }
80
89
        public var length(getLength,null) : Int;
81
90
        public var nfields(getNFields,null) : Int;
82
91
        private var __r : Void;
 
92
        private var __c : Void;
83
93
        private var cache : Dynamic;
84
94
 
85
 
        public function new(r) {
 
95
        public function new(r, c) {
86
96
                __r = r;
 
97
                __c = c;
87
98
        }
88
99
 
89
100
        private function getLength() {
90
101
                if(untyped __physeq__(__r, true))
91
 
                        return untyped __call__("mysql_affected_rows");
 
102
                        return untyped __call__("mysql_affected_rows", __c);
92
103
                else if (untyped __physeq__(__r, false))
93
104
                        return 0;
94
105
                return untyped __call__("mysql_num_rows", __r);
95
106
        }
96
 
        
 
107
 
97
108
        private var _nfields : Int;
98
109
        private function getNFields() {
99
110
                if(_nfields == null)
105
116
        private function getFieldsDescription() {
106
117
                if(_fieldsDesc == null) {
107
118
                        _fieldsDesc = [];
108
 
                        for(i in 0...nfields) {
109
 
                                _fieldsDesc.push({
 
119
                        for (i in 0...nfields) {
 
120
                                var item = {
110
121
                                        name : untyped __call__("mysql_field_name", __r, i),
111
122
                                        type : untyped __call__("mysql_field_type", __r, i)
112
 
                                });
 
123
                                };
 
124
                                _fieldsDesc.push(item);
113
125
                        }
114
126
                }
115
127
                return _fieldsDesc;
116
128
        }
117
129
 
118
130
        private function convert(v : String, type : String) : Dynamic {
119
 
                if(v == null) return v;
 
131
                if (v == null) return v;
120
132
                switch(type) {
121
 
                        case "year", "int":
 
133
                        case "int", "year":
122
134
                                return untyped __call__("intval", v);
123
135
                        case "real":
124
136
                                return untyped __call__("floatval", v);
140
152
                cRow = untyped __call__("mysql_fetch_array", __r, __php__("MYSQL_NUM"));
141
153
                return ! untyped __physeq__(cRow, false);
142
154
        }
143
 
        
 
155
 
144
156
        public function next() : Dynamic {
145
157
                if( cache != null ) {
146
158
                        var t = cache;
164
176
        }
165
177
 
166
178
        public function getResult( n : Int ) : String {
167
 
                if(cRow == null) 
 
179
                if(cRow == null)
168
180
                        if(!fetchRow())
169
181
                                return null;
170
182
                return cRow[n];