mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 21:19:01 -04:00
Gone is the ugly KORE_PGSQL macro that hid an overly complex state machine for the pgsql api. Gone is the pgsql array that was attached to http_requests. Gone are the callback hacks inside the pgsql api. Instead, I strongly encourage people to use the new state machine api Kore offers to properly deal with asynchronous queries. The pgsql example in examples/pgsql has been updated to reflect these changes.
61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2014 Joris Vink <joris@coders.se>
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _H_KORE_PGSQL
|
|
#define _H_KORE_PGSQL
|
|
|
|
#include <libpq-fe.h>
|
|
|
|
struct pgsql_conn {
|
|
u_int8_t type;
|
|
u_int8_t flags;
|
|
|
|
PGconn *db;
|
|
struct pgsql_job *job;
|
|
TAILQ_ENTRY(pgsql_conn) list;
|
|
};
|
|
|
|
struct kore_pgsql {
|
|
u_int8_t state;
|
|
char *error;
|
|
PGresult *result;
|
|
struct pgsql_conn *conn;
|
|
};
|
|
|
|
extern u_int16_t pgsql_conn_max;
|
|
extern char *pgsql_conn_string;
|
|
|
|
void kore_pgsql_init(void);
|
|
void kore_pgsql_handle(void *, int);
|
|
void kore_pgsql_cleanup(struct kore_pgsql *);
|
|
void kore_pgsql_continue(struct http_request *,
|
|
struct kore_pgsql *);
|
|
int kore_pgsql_async(struct kore_pgsql *,
|
|
struct http_request *, const char *);
|
|
|
|
int kore_pgsql_ntuples(struct kore_pgsql *);
|
|
void kore_pgsql_logerror(struct kore_pgsql *);
|
|
char *kore_pgsql_getvalue(struct kore_pgsql *, int, int);
|
|
|
|
#define KORE_PGSQL_STATE_INIT 1
|
|
#define KORE_PGSQL_STATE_WAIT 2
|
|
#define KORE_PGSQL_STATE_RESULT 3
|
|
#define KORE_PGSQL_STATE_ERROR 4
|
|
#define KORE_PGSQL_STATE_DONE 5
|
|
#define KORE_PGSQL_STATE_COMPLETE 6
|
|
|
|
#endif
|