Commit e187902d7a9173e00c3c87d76c26ec5b0e1d8e79

Authored by Alain Prouté
1 parent 75039758

-

Showing 1 changed file with 34 additions and 20 deletions   Show diff stats
anubis_dev/library/data_base/postgres_client.anubis
@@ -998,7 +998,7 @@ define Result(PG_Error,PG_Connection) @@ -998,7 +998,7 @@ define Result(PG_Error,PG_Connection)
998 { 998 {
999 error(msg) then error(ssl_error(msg)), 999 error(msg) then error(ssl_error(msg)),
1000 ok(ssl_conn) then 1000 ok(ssl_conn) then
1001 - print("Connected under SSL.\n"); 1001 + //print("Connected under SSL.\n");
1002 ok(pg_connection( 1002 ok(pg_connection(
1003 (Int n) |-> read(ssl_conn,n,10), 1003 (Int n) |-> read(ssl_conn,n,10),
1004 (ByteArray b) |-> if write(ssl_conn,b) is 1004 (ByteArray b) |-> if write(ssl_conn,b) is
@@ -1040,7 +1040,7 @@ define (Word8, ByteArray, Backend_Message) // (type, content, recognized messa @@ -1040,7 +1040,7 @@ define (Word8, ByteArray, Backend_Message) // (type, content, recognized messa
1040 failure then (type, 1040 failure then (type,
1041 constant_byte_array(0,0), 1041 constant_byte_array(0,0),
1042 unreadable_message(type,length,constant_byte_array(0,0))), 1042 unreadable_message(type,length,constant_byte_array(0,0))),
1043 - success(content) then show(b+content); 1043 + success(content) then //show(b+content);
1044 (type, 1044 (type,
1045 content, 1045 content,
1046 recognize_raw_msg(type,length,content)) 1046 recognize_raw_msg(type,length,content))
@@ -1076,11 +1076,11 @@ define Result(PG_Error,List(List(ByteArray))) @@ -1076,11 +1076,11 @@ define Result(PG_Error,List(List(ByteArray)))
1076 List(List(ByteArray)) so_far 1076 List(List(ByteArray)) so_far
1077 ) = 1077 ) =
1078 if get_next_response(show,read) is (type,content,msg) then 1078 if get_next_response(show,read) is (type,content,msg) then
1079 - if msg is ready_for_query(_) then ok(reverse(so_far)) else 1079 + if msg is ready_for_query(_) then ok(reverse(so_far)) else
1080 if msg is data_row(l) then read_complete_table_data(show,read,[l . so_far]) else 1080 if msg is data_row(l) then read_complete_table_data(show,read,[l . so_far]) else
1081 - if msg is unreadable_message(t,l,b) then error(unreadable_message(t,b)) else  
1082 - if msg is unknown_message(t,l,b) then error(unknown_message(t,b)) else  
1083 - if msg is error_response(s,c,m1,m2) then error(error_response(s,c,m1,m2)) else 1081 + if msg is unreadable_message(t,l,b) then error(unreadable_message(t,b)) else
  1082 + if msg is unknown_message(t,l,b) then error(unknown_message(t,b)) else
  1083 + if msg is error_response(s,c,m1,m2) then error(error_response(s,c,m1,m2)) else
1084 // all others are ignored: 1084 // all others are ignored:
1085 read_complete_table_data(show,read,so_far). 1085 read_complete_table_data(show,read,so_far).
1086 1086
@@ -1099,6 +1099,31 @@ define List((Word8,ByteArray)) @@ -1099,6 +1099,31 @@ define List((Word8,ByteArray))
1099 1099
1100 *** [2.4] Making the query function. 1100 *** [2.4] Making the query function.
1101 1101
  1102 + An auxiliary function for getting all responses dropping those we don't care about.
  1103 +
  1104 +define PG_Answer
  1105 + get_all_responses
  1106 + (
  1107 + ByteArray -> One show,
  1108 + Int -> Maybe(ByteArray) read
  1109 + ) =
  1110 + if get_next_response(show,read) is (type,content,first_msg) then
  1111 + if first_msg is notice_response(_) then get_all_responses(show,read) else
  1112 + if first_msg is row_description(cols)
  1113 + then if read_complete_table_data(show,read,[]) is
  1114 + {
  1115 + error(e) then forget(wait_for_ready(show,read)); error(e),
  1116 + ok(data) then table(cols,data)
  1117 + } else
  1118 + if first_msg is command_complete(tag)
  1119 + then forget(wait_for_ready(show,read)); command_complete(tag) else
  1120 + if first_msg is error_response(s,c,m1,m2) then
  1121 + (forget(wait_for_ready(show,read)); error(error_response(s,c,m1,m2)))
  1122 + else
  1123 + message_list(read_all_messages(show,read,[(type,content)])).
  1124 +
  1125 +
  1126 +
1102 define (String query) -> PG_Answer 1127 define (String query) -> PG_Answer
1103 make_query_function 1128 make_query_function
1104 ( 1129 (
@@ -1112,19 +1137,8 @@ define (String query) -> PG_Answer @@ -1112,19 +1137,8 @@ define (String query) -> PG_Answer
1112 { 1137 {
1113 failure then error(cannot_write_to_connection), 1138 failure then error(cannot_write_to_connection),
1114 success(_) then 1139 success(_) then
1115 - show(fq);  
1116 - if get_next_response(show,read) is (type,content,first_msg) then  
1117 - if first_msg is row_description(cols)  
1118 - then if read_complete_table_data(show,read,[]) is  
1119 - {  
1120 - error(e) then forget(wait_for_ready(show,read)); error(e),  
1121 - ok(data) then table(cols,data)  
1122 - } else  
1123 - if first_msg is command_complete(tag)  
1124 - then forget(wait_for_ready(show,read)); command_complete(tag) else  
1125 - if first_msg is error_response(s,c,m1,m2) then  
1126 - (forget(wait_for_ready(show,read)); error(error_response(s,c,m1,m2))) else  
1127 - message_list(read_all_messages(show,read,[(type,content)])) 1140 + //show(fq);
  1141 + get_all_responses(show,read)
1128 }. 1142 }.
1129 1143
1130 1144
@@ -1192,7 +1206,7 @@ define Result(PG_Error,One) @@ -1192,7 +1206,7 @@ define Result(PG_Error,One)
1192 { 1206 {
1193 failure then error(cannot_write_to_connection), 1207 failure then error(cannot_write_to_connection),
1194 success(_) then 1208 success(_) then
1195 - show(constant_byte_array(1,'L')+msg); 1209 + //show(constant_byte_array(1,'L')+msg);
1196 if get_next_response(show,read) is (type,content,next) then 1210 if get_next_response(show,read) is (type,content,next) then
1197 if next is unreadable_message(t,_,b) then error(unreadable_message(t,b)) else 1211 if next is unreadable_message(t,_,b) then error(unreadable_message(t,b)) else
1198 if next is unknown_message(t,_,b) then error(unknown_message(t,b)) else 1212 if next is unknown_message(t,_,b) then error(unknown_message(t,b)) else