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
  
120
  
121
  
122
  
/* 
 * Glue for the ODBC-module 
 */ 
 
#pike __REAL_VERSION__ 
#require constant(Odbc.odbc) 
 
// Cannot dump this since the #require check may depend on the 
// presence of system libs at runtime. 
optional constant dont_dump_program = 1; 
 
inherit Odbc.odbc; 
 
constant list_dbs = Odbc.list_dbs; 
 
//! 
class TypedResult 
{ 
  inherit ::this_program; 
 
  //! Value to use to represent NULL. 
  mixed _null_value = Val.null; 
 
  //! Function called by @[user_defined_factory()] to create values for 
  //! custom types. 
  function(string(0..255), mapping(string:mixed), int: mixed) user_defined_cb; 
 
  //! Helper function that scales @[mantissa] by a 
  //! factor @expr{10->pow(scale)@}. 
  //! 
  //! @returns 
  //!   Returns an @[Gmp.mpq] object if @[scale] is negative, 
  //!   and otherwise an integer (bignum). 
  object(Gmp.mpq)|int scale_numeric(int mantissa, int scale) 
  { 
    if (!scale) return mantissa; 
    if (scale > 0) { 
      return mantissa * 10->pow(scale); 
    } 
    return Gmp.mpq(mantissa, 10->pow(-scale)); 
  } 
 
  //! Time of day. 
  class TOD(int hour, int minute, int second, int|void nanos) 
  { 
    protected string _sprintf(int c) 
    { 
      if (nanos) { 
        return sprintf("%02d:%02d:%02d.%09d", 
                       hour, minute, second, nanos); 
      } 
      return sprintf("%02d:%02d:%02d", hour, minute, second); 
    } 
 
    protected mixed cast(string t) 
    { 
      switch(t) { 
      case "string": 
        return _sprintf('s'); 
      case "int": 
        // Number of seconds since the start of the day. 
        return (hour*60 + minute)*60 + second; 
      case "float": 
        int seconds = cast("int"); 
        return seconds + nanos/1000000000.0; 
      } 
      return UNDEFINED; 
    } 
  } 
 
  //! Function called to create time of day objects. 
  //! 
  //! The default implementation just passes along its 
  //! arguments to @[TOD]. 
  TOD time_factory(int hour, int minute, int second, int|void nanos) 
  { 
    return TOD(hour, minute, second, nanos); 
  } 
 
  //! Function called to create timestamp and date objects. 
  //! 
  //! @note 
  //!   The @[tz_hour] and @[tz_minute] arguments are currently 
  //!   neither generated by the low-level code, nor used by 
  //!   the current implementation of the function. 
  Calendar.ISO.Day|Calendar.ISO.Fraction timestamp_factory(int year, 
                                                           int month, 
                                                           int day, 
                                                           int|void hour, 
                                                           int|void minute, 
                                                           int|void second, 
                                                           int|void nanos, 
                                                           int|void tz_hour, 
                                                           int|void tz_minute) 
  { 
    if (query_num_arg() <= 3) { 
      return Calendar.ISO.Day(year, month, day); 
    } 
    return Calendar.ISO.Fraction(year, month, day, 
                                 hour, minute, second, nanos); 
  } 
 
  //! Function called to create UUID/GUID objects. 
  Standards.UUID.UUID uuid_factory(string(0..255) raw_uuid) 
  { 
    return Standards.UUID.UUID(raw_uuid); 
  } 
 
  //! Function called to create representations of user-defined types. 
  //! 
  //! The default implementation just calls @[user_defined_cb] if 
  //! it has been set, and otherwise returns @[raw]. 
  mixed user_defined_factory(string(0..255) raw, 
                             mapping(string:mixed) field_info, 
                             int field_number) 
  { 
    if (user_defined_cb) return user_defined_cb(raw, field_info, field_number); 
    return raw; 
  } 
}