EnglishРусский  

   ..

   odbc.g

   odbcfield.g

Данный проект закрыт! Создан новый скриптовый язык с тем же именем. Всё доступно на GitHub.
Также попробуйте нашу open source кроссплатформенную программу для создания и управления скриптами.

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\lib\odbc\odbcfield.g
  1 /*******************************************************************************
  2 <fieldsql>
  3 ODBC Library    
  4 <copyright author="Alexander Krivonogov" year=2006 
  5 file="This file is part of the Gentee GUI library."></>
  6    <description>
  7 Definition of 'win' type.
  8    </>
  9 </>
 10 *******************************************************************************/
 11 //include { "odbcquery.ge" }
 12 /*extern {
 13 
 14 method uint odbcquery.getlongdata( odbcfield f, str val )
 15 }*/
 16 type odbcfield {
 17    str  name
 18    str  val
 19    int  sqlind
 20    uint sqltype
 21    uint sqlsize
 22    uint sqldecdig
 23    uint vtype
 24    uint hstmt//query
 25    uint index
 26 }
 27 
 28 type numeric {
 29   long   val
 30   uint   scale 
 31 }
 32 
 33 type timestamp {
 34   ushort year      
 35   ushort month      
 36   ushort day     
 37   ushort hour      
 38   ushort minute      
 39   ushort second      
 40   uint   fraction
 41 }
 42 
 43 method uint odbcfield.getsqltype()
 44 {
 45    return this.sqltype  
 46 }
 47 
 48 method uint odbcfield.getsqlsize()
 49 {
 50    return this.sqlsize
 51 }
 52 
 53 /*-----------------------------------------------------------------------------
 54 * Id: odbcfield_isnull F3
 55 *
 56 * Summary: Determines if the field contains the NULL value. 
 57 *  
 58 * Return: Returns nonzero, if the field contains the NULL value; otherwise, 
 59           it returns zero. 
 60 *
 61 -----------------------------------------------------------------------------*/
 62 
 63 method uint odbcfield.isnull()
 64 {
 65    return this.sqlind == -1 
 66 }
 67 
 68 /*-----------------------------------------------------------------------------
 69 * Id: odbcfield_getdatetime F2
 70 *
 71 * Summary: Gets the field's value as a value of the datetime type. This method
 72            is applied for fields that contain date and/or time.
 73 *
 74 * Params: dt - Result #a(tdatetime) object.    
 75 *  
 76 * Return: #lng/retpar( dt )  
 77 *
 78 -----------------------------------------------------------------------------*/
 79 
 80 method datetime odbcfield.getdatetime( datetime dt )
 81 {
 82    if this.vtype == datetime 
 83    {
 84       uint ts = this.val.ptr()
 85       ts as timestamp      
 86       dt.year = ts.year                      
 87       dt.month = ts.month    
 88       dt.day = ts.day       
 89       dt.hour = ts.hour              
 90       dt.minute = ts.minute                  
 91       dt.second = ts.second                              
 92       dt.msec  = ts.fraction / 1000000
 93       dt.dayofweek = dt.dayofweek()       
 94    }   
 95    return dt
 96 }
 97 
 98 /*-----------------------------------------------------------------------------
 99 * Id: odbcfield_getbuf F2
100 *
101 * Summary: Gets the field's value as a value of the buf type (the binary data).
102            This method is applied for fields with binary data. 
103 *
104 * Params: dest - Result #b(buf) object.     
105 *  
106 * Return: #lng/retpar( dest )  
107 *
108 -----------------------------------------------------------------------------*/
109 
110 method buf odbcfield.getbuf( buf dest )
111 {
112    if this.isnull()
113    {
114       dest.clear()
115       return dest//="NULL"
116    }
117    //if this.sqlind > this.sqlsize
118    if this.vtype == buf 
119    {  
120       //if !*this.val
121       {             
122          uint newsize
123          SQLGetData( this.hstmt, this.index + 1, $SQL_BINARY, this.val.ptr(),
124             0, &newsize )               
125          this.val->buf.expand( newsize + 1 ) 
126          SQLGetData( this.hstmt, this.index + 1, $SQL_BINARY, this.val.ptr(),
127             newsize + 1, &newsize )
128          this.val.setlen( newsize )
129          /*this.val->buf.expand( this.sqlind + 1 ) 
130          SQLGetData( this.hstmt, this.index + 1, $SQL_BINARY, this.val.ptr(),
131             this.sqlind + 1, &this.sqlind )*/
132       }
133       dest.copy( this.val->buf.ptr(), this.sqlind );        
134    }   
135    return dest
136 }
137 
138 /*-----------------------------------------------------------------------------
139 * Id: odbcfield_getstr F2
140 *
141 * Summary: Get the field's value as a string of the #b(str) type. This method 
142            is applied for fields that contain a string, a date, time and 
143            numeric fields. 
144 *
145 * Params: dest - Result #b(str) object.     
146 *  
147 * Return: #lng/retpar( dest )  
148 *
149 -----------------------------------------------------------------------------*/
150 
151 method str odbcfield.getstr( str dest )
152 {
153    if this.isnull(): return dest.clear()//="NULL"
154    if this.vtype == str 
155    {      
156       if !this.sqlsize  
157       {         
158          //if !*this.val 
159          {                   
160             uint newsize
161             SQLGetData( this.hstmt, this.index + 1, $SQL_CHAR, this.val.ptr(),
162                0, &newsize )               
163             this.val->buf.expand( newsize + 1 ) 
164             SQLGetData( this.hstmt, this.index + 1, $SQL_CHAR, this.val.ptr(),
165                newsize + 1, &newsize )
166             this.val.setlen( newsize )
167          }  
168       }
169       return dest.copy( this.val.ptr() )
170    }
171    elif this.vtype == numeric : return dest.copy( this.val.ptr() )
172    
173    dest.clear()   
174    if this.vtype == int : dest@this.val.ptr()->int
175    elif this.vtype == long : dest@this.val.ptr()->long    
176    elif this.vtype == double : dest@this.val.ptr()->double 
177    elif this.vtype == datetime 
178    {
179       datetime dt
180       str d, t      
181       this.getdatetime( dt )    
182       getdatetime( dt, d, t )      
183       dest = d +" "+ t
184    }
185    return dest
186 }
187 
188 /*-----------------------------------------------------------------------------
189 * Id: odbcfield_getint_1 FB
190 *
191 * Summary: Gets the field's value as an unsigned integer. This method is 
192            applied for fields that contain integers (the storage size is up 
193            to 4 bytes). 
194 *  
195 * Return: Returns the field's value. 
196 *
197 -----------------------------------------------------------------------------*/
198 
199 method uint odbcfield.getuint()
200 {
201    if this.vtype == int : return this.val.ptr()->uint   
202    return 0      
203 }
204 
205 /*-----------------------------------------------------------------------------
206 * Id: odbcfield_getint F3
207 *
208 * Summary: Gets the field's value as an integer. This method is applied for
209            fields that contain integers (the storage size is up to 4 bytes).  
210 *  
211 * Return: Returns the field's value. 
212 *
213 -----------------------------------------------------------------------------*/
214 
215 method int odbcfield.getint()
216 {
217    if this.vtype == int : return this.val.ptr()->int   
218    return 0
219 }
220 
221 /*-----------------------------------------------------------------------------
222 * Id: odbcfield_getlong F3
223 *
224 * Summary: Get the field's value as a number of the long type. This method 
225            is applied for fields that contain long integers (8 bytes).  
226 *  
227 * Return: Returns the field's value. 
228 *
229 -----------------------------------------------------------------------------*/
230 
231 method long odbcfield.getlong()
232 {
233    if this.vtype == long : return this.val.ptr()->long   
234    return 0l      
235 }
236 
237 /*-----------------------------------------------------------------------------
238 * Id: odbcfield_getlong_1 FB
239 *
240 * Summary: Get the field's value as a number of the #b(ulong) type. This 
241            method is applied for fields that contain long integers (8 bytes).  
242 *  
243 * Return: Returns the field's value. 
244 *
245 -----------------------------------------------------------------------------*/
246 
247 method ulong odbcfield.getulong()
248 {
249    if this.vtype == long : return this.val.ptr()->ulong   
250    return 0l      
251 }
252 
253 /*-----------------------------------------------------------------------------
254 * Id: odbcfield_getnumeric F2
255 *
256 * Summary: Gets the field's value as a fixed point number. This method is
257            applied for fields that contain fixed point numbers. The structure 
258            is applied for data of this type, as follows: #srcg[ 
259 |type numeric {
260 |   long val
261 |   uint scale 
262 |}]
263            The #b(val) field contains the integer representation of a number,
264            and the #b(scale) field indicates how many times val is divided 
265            by 10 in order to get a real number (a precision number). 
266 *
267 * Params: num - Result numeric structure.    
268 *  
269 * Return: #lng/retpar( num )  
270 *
271 -----------------------------------------------------------------------------*/
272 
273 method numeric odbcfield.getnumeric( numeric num )
274 {
275    uint i
276    long value
277    uint pr = 0, scale = 0, sign = 0
278    
279    fornum i = 0, $NUMERIC_SIZE
280    {      
281       if this.val[i]== 0 : break
282       if this.val[i]>='0' && this.val[i]<='9'
283       {
284          value *= 10l
285          value += long( this.val[i] & 0x0F )    
286          pr++  
287       }
288       elif this.val[i]=='.'
289       {
290          scale = pr  
291       }
292       elif this.val[i]=='-'
293       {
294          sign = 1
295       }         
296    }
297    if scale : scale = pr - scale
298    if sign : value = -value
299    num.scale = scale
300    num.val = value   
301    return num   
302 }
303 
304 /*-----------------------------------------------------------------------------
305 * Id: odbcfield_getdouble F3
306 *
307 * Summary: Gets the field's value as a floating-point number. This method 
308            is applied for fields that contain floating-point numbers.
309 *  
310 * Return: Returns the field's value. 
311 *
312 -----------------------------------------------------------------------------*/
313 
314 method double odbcfield.getdouble()
315 {
316    if this.vtype == double : return this.val.ptr()->double
317    if this.vtype == int : return double( this.val.ptr()->int )
318    if this.vtype == long : return double( this.val.ptr()->long )
319    if this.vtype == numeric 
320    {
321       numeric num
322       double value 
323       uint i
324       
325       this.getnumeric( num )
326       value = double( num.val )
327       fornum i = 0, num.scale: value /= 10d
328       return value
329    }      
330    return 0d     
331 }
332 
333 /*-----------------------------------------------------------------------------
334 * Id: odbcfield_gettype F3
335 *
336 * Summary: Gets a type of the field's value. Returns the identifier of one 
337            of the following types: 
338            #b( 'buf, str, int, long, numeric, double, datetime'). 
339 *  
340 * Return: Type identifier.  
341 *
342 -----------------------------------------------------------------------------*/
343 
344 method uint odbcfield.gettype()
345 {
346    return this.vtype
347 }
348 
349 /*-----------------------------------------------------------------------------
350 * Id: odbcfield_getname F2
351 *
352 * Summary: Gets a field's name. 
353 *
354 * Params: result - Result string.     
355 *  
356 * Return: #lng/retpar( result )  
357 *
358 -----------------------------------------------------------------------------*/
359 
360 method str odbcfield.getname( str result )
361 {
362    result = this.name
363    return result
364 }
365 
366 /*-----------------------------------------------------------------------------
367 ** Id: odbcfield_getindex F3
368 *
369 * Summary: Gets the field index number.
370 *  
371 * Return: Field index number. 
372 *
373 -----------------------------------------------------------------------------*/
374 
375 method uint odbcfield.getindex()
376 {
377    return this.index
378 }
379 
Редактировать