00001
00002
00003
00004
00005 #if !defined(_INCLUDED_SUL_PEERS_H_HEADER__)
00006 #define _INCLUDED_SUL_PEERS_H_HEADER__
00007
00017 typedef void* sul_objectptr_t;
00018
00023 typedef enum sul_field_key_type_e
00024 {
00025 SUL_FIELD_KT_NONE = -1,
00026 SUL_FIELD_KT_ID = 0,
00027 SUL_FIELD_KT_NAME,
00028 SUL_FIELD_KT_IP,
00029 SUL_FIELD_KT_LAST
00030 } sul_field_key_type_e;
00031
00036 typedef enum sul_field_flags_e
00037 {
00038 SUL_FIELD_FLAG_NONE = 0,
00039 SUL_FIELD_FLAG_PK,
00040 SUL_FIELD_FLAG_FK
00041 } sul_field_flags_e;
00042
00048 typedef enum sul_field_type_e
00049 {
00051 SUL_FIELD_TYPE_NULL = 0,
00053 SUL_FIELD_TYPE_STRING,
00055 SUL_FIELD_TYPE_INTEGER,
00057 SUL_FIELD_TYPE_BOOLEAN,
00059 SUL_FIELD_TYPE_FK,
00061 SUL_FIELD_TYPE_REAL,
00063 SUL_FIELD_TYPE_TIMESTAMP,
00065 SUL_FIELD_TYPE_TIME,
00067 SUL_FIELD_TYPE_DATE
00068 } sul_field_type_e;
00069
00074 typedef struct sul_objfield_t
00075 {
00076 char *name;
00077 sul_field_type_e type;
00078 size_t off;
00079 apr_int16_t flags;
00080 sul_field_key_type_e key_type;
00081 } sul_objfield_t;
00082
00088 typedef struct sul_objpeer_t
00089 {
00090 char *name;
00091 char *table;
00092 char *seq;
00093 apr_int32_t objsz;
00094 sul_objfield_t* fields;
00095 sul_objfield_t* pkey;
00096 sul_boolean_t ready;
00097 } sul_objpeer_t;
00098
00104 #define SUL_PEER_NAME(table) peer_##table##_peer
00105
00111 #define SUL_PEER_PTR(table) &(SUL_PEER_NAME(table))
00112
00117 #define SUL_PEER_DECLARE(table) \
00118 extern sul_objpeer_t SUL_PEER_NAME(table)
00119
00127 #define SUL_PEER_IMPLEMENT(type, table) \
00128 sul_objpeer_t SUL_PEER_NAME(table) = { \
00129 #type, \
00130 #table, \
00131 #table "_id", \
00132 sizeof(type), \
00133 peer_##table##_fields, \
00134 FALSE \
00135 }
00136
00137 #define SUL_PEER_IMPLEMENT_SEQ(type, table, seq) \
00138 sul_objpeer_t SUL_PEER_NAME(table) = { \
00139 #type, \
00140 #table, \
00141 #seq, \
00142 sizeof(type), \
00143 peer_##table##_fields, \
00144 FALSE \
00145 }
00146
00152 #define SUL_PEER_FIELDS_BEGIN(table) sul_objfield_t peer_##table##_fields[] = {
00153
00160 #define SUL_PEER_FIELDS_FIELD(name, type) { name, type, 0, SUL_FIELD_FLAG_NONE, SUL_FIELD_KT_NONE }
00161
00170 #define SUL_PEER_FIELDS_FIELD_KEY(name, type, id) { name, type, 0, SUL_FIELD_FLAG_NONE, id }
00171
00178 #define SUL_PEER_FIELDS_PKFLD(name, type) { name, type, 0, SUL_FIELD_FLAG_PK, SUL_FIELD_KT_ID }
00179
00186 #define SUL_PEER_FIELDS_FKFLD(name, type) { name, type, 0, SUL_FIELD_FLAG_FK, SUL_FIELD_KT_NONE }
00187
00191 #define SUL_PEER_FIELDS_END() { NULL, SUL_FIELD_TYPE_NULL, 0, 0, 0 } }
00192
00197 typedef struct sul_peer_query_t
00198 {
00199 apr_pool_t *pool;
00200 char *sql;
00201 sul_dbc_t *dbc;
00202 sul_dbr_t *res;
00203 sul_objpeer_t *peer;
00204 } sul_peer_query_t;
00205
00209 typedef struct sul_dataobj_header_t
00210 {
00211 char bnew : 1;
00212 char modified : 7;
00213 } sul_dataobj_header_t;
00214
00218 typedef struct sul_peer_record_t
00219 {
00220 sul_objpeer_t *peer;
00221 apr_thread_rwlock_t *lock;
00222 } sul_peer_record_t;
00223
00234 SUL_DECLARE(sul_error_t *)
00235 sul_peer_initialize(sul_objpeer_t *peer);
00236
00247 SUL_DECLARE(sul_error_t *)
00248 sul_peer_query_execute(sul_peer_query_t **query, sul_objpeer_t *peer,
00249 sul_dbc_t *dbc, apr_pool_t *pool,
00250 const char *sql, ...);
00251
00259 SUL_DECLARE(apr_size_t)
00260 sul_peer_query_size(sul_peer_query_t *query);
00261
00272 SUL_DECLARE(sul_error_t *)
00273 sul_peer_generate_array(apr_array_header_t **arrayp,
00274 sul_peer_query_t *query, apr_pool_t *pool);
00275
00284 SUL_DECLARE(sul_error_t *)
00285 sul_peer_generate_single(sul_objectptr_t *ptr, sul_peer_query_t *query,
00286 apr_pool_t *pool);
00287
00297 SUL_DECLARE(apr_size_t)
00298 sul_peer_type_size(sul_field_type_e type);
00299
00310 SUL_DECLARE(sul_error_t *)
00311 sul_peer_field_to_sql(sul_stringbuf_t *sql, sul_objpeer_t *peer,
00312 sul_objectptr_t ptr, apr_size_t fldi,
00313 apr_pool_t *pool);
00314
00322 SUL_DECLARE(char *)
00323 sul_peer_sql_query(sul_objpeer_t *peer, apr_pool_t *pool);
00324
00333 SUL_DECLARE(char *)
00334 sul_peer_sql_add(sul_objpeer_t *peer, sul_objectptr_t ptr, apr_pool_t *pool);
00335
00344 SUL_DECLARE(char *)
00345 sul_peer_sql_update(sul_objpeer_t *peer, sul_objectptr_t ptr,
00346 apr_pool_t *pool);
00347
00356 SUL_DECLARE(char *)
00357 sul_peer_sql_delete(sul_objpeer_t *peer, sul_objectptr_t ptr,
00358 apr_pool_t *pool);
00359
00367 SUL_DECLARE(sul_key_t)
00368 sul_peer_object_key_get(sul_objpeer_t *peer, sul_objectptr_t ptr);
00369
00378 SUL_DECLARE(sul_key_t)
00379 sul_peer_object_key_set(sul_objpeer_t *peer, sul_objectptr_t ptr,
00380 sul_key_t key);
00381
00391 SUL_DECLARE(sul_error_t *)
00392 sul_peer_populate(sul_objectptr_t ptr, sul_peer_query_t *query,
00393 apr_size_t row, apr_pool_t *pool);
00394
00404 SUL_DECLARE(sul_error_t *)
00405 sul_peer_save(sul_objpeer_t *peer, sul_objectptr_t ptr,
00406 sul_dbc_t *dbc, apr_pool_t *pool);
00407
00417 SUL_DECLARE(sul_error_t *)
00418 sul_peer_add(sul_objpeer_t *peer, sul_objectptr_t ptr,
00419 sul_dbc_t *dbc, apr_pool_t *pool);
00420
00430 SUL_DECLARE(sul_error_t *)
00431 sul_peer_delete(sul_objpeer_t *peer, sul_objectptr_t ptr,
00432 sul_dbc_t *dbc, apr_pool_t *pool);
00433
00439 SUL_DECLARE(signed)
00440 sul_parse_time(apr_time_exp_t *tm, const char *str);
00441
00444 #endif