static int exec_builtin(SQL *conn, History *hist, char *query) { (void) conn; (void) hist; if(!strncmp(query, "\\q", 2)) { exit(EXIT_SUCCESS); } if(!strncmp(query, "\\c", 2)) { query += 2; while(isspace(*query)) query++; if(!*query) { printf("[08000] Specify \"\\c URI\" to establish a new connection\n"); return -1; } conn = sql_connect(query); if(!conn) { printf("[%s] %s\n", sql_sqlstate(NULL), sql_error(NULL)); return -1; } if(sql_conn) { sql_disconnect(sql_conn); } sql_conn = conn; return 0; } printf("[42000] Unknown command '%s'\n", query); return -1; }
int main(int arg, char *args[]) { sql_connect(&mysql, &conn); //如果没有参数,main函数返回 if(arg < 2) { printf("usage:myserver port\n"); return EXIT_FAILURE; } //setdaemon(); //将第一个参数转化为整数 int iport = atoi(args[1]); if(iport == 0) { printf("port %d is invalid\n", iport); return EXIT_FAILURE; } int st = socket_create(iport); socket_accept(st); sql_disconnect(conn); close(st); printf("myhttp is end\n"); return 0; }
void db_sql_unref(struct sql_connection **_conn) { struct sql_connection *conn = *_conn; /* abort all pending auth requests before setting conn to NULL, so that callbacks can still access it */ sql_disconnect(conn->db); *_conn = NULL; if (--conn->refcount > 0) return; sql_deinit(&conn->db); pool_unref(&conn->pool); }
void sql_destroy(void) { sql_result_t *r; sql_result_t *r0; sql_disconnect(); r=_sql_result_root; while(r) { r0 = r->next; sql_reset_result(r); pkg_free(r); r = r0; } }