84 * |
84 * |
85 * The query has been aborted, it will simply be freed |
85 * The query has been aborted, it will simply be freed |
86 */ |
86 */ |
87 static void _evsql_query_done (struct evsql_query *query, struct evsql_result *res) { |
87 static void _evsql_query_done (struct evsql_query *query, struct evsql_result *res) { |
88 if (res) { |
88 if (res) { |
89 if (query->cb_fn) |
89 if (query->cb_fn) { |
90 // call the callback |
90 // call the callback |
91 query->cb_fn(res, query->cb_arg); |
91 query->cb_fn(res, query->cb_arg); |
92 else { |
92 |
|
93 } else { |
93 WARNING("supressing cb_fn because query was aborted"); |
94 WARNING("supressing cb_fn because query was aborted"); |
94 |
95 |
95 // free the results |
96 // free the results |
96 evsql_result_free(res); |
97 evsql_result_free(res); |
97 } |
98 } |
911 _evsql_trans_rollback(trans, NULL); |
913 _evsql_trans_rollback(trans, NULL); |
912 |
914 |
913 } |
915 } |
914 } |
916 } |
915 |
917 |
|
918 void evsql_destroy (struct evsql *evsql) { |
|
919 struct evsql_query *query; |
|
920 struct evsql_conn *conn; |
|
921 |
|
922 // kill off all queued queries |
|
923 while ((query = TAILQ_FIRST(&evsql->query_queue)) != NULL) { |
|
924 // just free it, command first |
|
925 free(query->command); query->command = NULL; |
|
926 _evsql_query_free(query); |
|
927 } |
|
928 |
|
929 // kill off all connections |
|
930 while ((conn = LIST_FIRST(&evsql->conn_list)) != NULL) { |
|
931 // kill off the query |
|
932 if (conn->query) { |
|
933 free(query->command); query->command = NULL; |
|
934 _evsql_query_free(query); |
|
935 |
|
936 conn->query = NULL; |
|
937 } |
|
938 |
|
939 // kill off the transaction |
|
940 if (conn->trans) { |
|
941 conn->trans->query = NULL; |
|
942 _evsql_trans_release(conn->trans); |
|
943 } |
|
944 |
|
945 // kill it off |
|
946 _evsql_conn_release(conn); |
|
947 } |
|
948 |
|
949 // then free the evsql itself |
|
950 free(evsql); |
|
951 } |
|
952 |
|
953 void _evsql_destroy_handler (int fd, short what, void *arg) |
|
954 { |
|
955 struct evsql *evsql = arg; |
|
956 |
|
957 evsql_destroy(evsql); |
|
958 } |
|
959 |
|
960 evsql_err_t evsql_destroy_next (struct evsql *evsql) |
|
961 { |
|
962 struct timeval tv = {0, 0}; |
|
963 |
|
964 // schedule a one-time event |
|
965 return event_base_once(evsql->ev_base, 0, EV_TIMEOUT, &_evsql_destroy_handler, evsql, &tv); |
|
966 } |
|
967 |