metaSQL_Postgres.anubis
6.44 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
The Anubis Project
The Postgres dependant stuff for metaSQL.
read tools/basis.anubis
read data_base/metaSQL.anubis
read data_base/postgres_client.anubis
public define Maybe(MetaSQL_Specific)
metaSQL_make_specific
(
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
).
The same one but with encrypted connection to the database.
public define Maybe(MetaSQL_Specific)
metaSQL_make_specific
(
String server_name,
(Maybe(X509)) -> Bool accept_policy, // see web/multihost_http_server.anubis
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
).
--- That's all for the public part ! --------------------------------------------------
define One
print
(
List(MaybeNull(ByteArray)) l
) =
if l is
{
[ ] then print(" |\n"),
[h . t] then print(" | "+
if h is
{
null then "NULL",
not_null(ba) then to_string(ba)
}); print(t)
}.
define String -> MetaSQL_Answer
pg_to_meta
(
String -> PG_Answer qf
) =
(String q) |-> if qf(q) is
{
error(msg) then error(format(msg)),
command_complete(msg) then command_complete,
table(columns,rows) then table(rows),
message_list(infos) then informations(concat(map(
((Word8, ByteArray) p) |-> if p is (c,b) then to_decimal(c)+" "+to_string(b),infos),"\n"))
}.
define String
to_database_type
(
MetaSQL_Type t
) =
if t is
{
anubis(_T) then "text",
binary then "text"
binary_or_null then "text"
boolean then "boolean"
boolean_or_null then "boolean"
date then "date"
date_or_null then "date"
time then "time"
time_or_null then "time"
datetime then "timestamp"
datetime_or_null then "timestamp"
foreign(String table_name) then "integer"
foreign_or_null(String table_name) then "integer"
integer16 then "integer"
integer16_or_null then "integer"
integer32 then "integer"
integer32_or_null then "integer"
integer then "integer"
integer_or_null then "integer"
char(Int size) then "varchar("+size+")"
char_or_null(Int size) then "varchar("+size+")"
text then "text"
text_or_null then "text"
}.
define Maybe(String -> MetaSQL_Answer)
make_query_function
(
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
) =
if open_PG_connection
(
none,
ip_address,
ip_port,
user_name,
password,
database_name,
(ByteArray a) |-> unique // debugging tool not used here
) is
{
error(pg_msg) then failure,
ok(qf) then success(pg_to_meta(qf))
}.
define Maybe(String -> MetaSQL_Answer)
make_query_function
(
String server_name,
(Maybe(X509)) -> Bool accept_policy,
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
) =
if open_PG_connection
(
ssl(server_name,accept_policy),
ip_address,
ip_port,
user_name,
password,
database_name,
(ByteArray a) |-> unique // debugging tool not used here
) is
{
error(pg_msg) then failure,
ok(qf) then success(pg_to_meta(qf))
}.
public define Maybe(MetaSQL_Specific)
metaSQL_make_specific
(
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
) =
if make_query_function(ip_address,ip_port,user_name,password,database_name) is
{
failure then failure,
success(qf) then
success(specific(database_name,qf,to_database_type))
}.
The same one but with encrypted connection to the database.
public define Maybe(MetaSQL_Specific)
metaSQL_make_specific
(
String server_name,
(Maybe(X509)) -> Bool accept_policy, // see web/multihost_http_server.anubis
Word32 ip_address,
Word32 ip_port, // usually: 5432 (IANA registered)
String user_name,
String password, // anything if no password required
String database_name,
) =
if make_query_function(server_name,accept_policy,ip_address,ip_port,user_name,password,database_name) is
{
failure then failure,
success(qf) then
success(specific(database_name,qf,to_database_type))
}.