Skip to content

Commit

Permalink
add pq.c3l
Browse files Browse the repository at this point in the history
  • Loading branch information
louis77 committed Dec 30, 2024
1 parent 971513f commit 9f0815d
Show file tree
Hide file tree
Showing 3 changed files with 361 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This repository contains external libraries for use with C3.
- OpenGL
- Vulkan (WIP)
- GLFW https://www.glfw.org/ - WIP
- PQ (PostgreSQL) https://www.postgresql.org/docs/current/libpq.html

## Guide for writing bindings

Expand Down
45 changes: 45 additions & 0 deletions libraries/pq.c3l/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"provides": "pq",
"targets": {
"macos-aarch64": {
"linked-libraries": [
"pq"
]
},
"macos-x64": {
"linked-libraries": [
"pq"
]
},
"linux-x64": {
"linked-libraries": [
"pq"
]
},
"linux-x86": {
"linked-libraries": [
"pq"
]
},
"openbsd-x86": {
"linked-libraries": [
"pq"
]
},
"openbsd-x64": {
"linked-libraries": [
"pq"
]
},
"freebsd-x64": {
"linked-libraries": [
"pq"
]
},
"freebsd-x86": {
"linked-libraries": [
"pq"
]
}
}
}
315 changes: 315 additions & 0 deletions libraries/pq.c3l/pq.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
// pq.c3i
// Binding originally created by Louis @ https://github.com/louis77

module pq;

/*
*
* pg.c3
* This file contains definitions for functions defined in libpq.
*
*/

def PGconn = void*;
def PGresult = void*;

enum ConnStatusType : CInt
{
OK,
BAD,
/* Non-blocking mode only below here */

/*
* The existence of these should never be relied upon - they should only
* be used for user feedback or similar purposes.
*/
STARTED, /* Waiting for connection to be made. */
MADE, /* Connection OK; waiting to send. */
AWAITING_RESPONSE, /* Waiting for a response from the
* postmaster. */
AUTH_OK, /* Received authentication; waiting for
* backend startup. */
SETENV, /* This state is no longer used. */
SSL_STARTUP, /* Performing SSL handshake. */
NEEDED, /* Internal state: connect() needed. */
CHECK_WRITABLE, /* Checking if session is read-write. */
CONSUME, /* Consuming any extra messages. */
GSS_STARTUP, /* Negotiating GSSAPI. */
CHECK_TARGET, /* Internal state: checking target server
* properties. */
CHECK_STANDBY, /* Checking if server is in standby mode. */
ALLOCATED, /* Waiting for connection attempt to be
* started. */
}

enum ExecStatusType : CInt
{
EMPTY_QUERY, /* empty query string was executed */
COMMAND_OK, /* a query command that doesn't return
* anything was executed properly by the
* backend */
TUPLES_OK, /* a query command that returns tuples was
* executed properly by the backend, PGresult
* contains the result tuples */
COPY_OUT, /* Copy Out data transfer in progress */
COPY_IN, /* Copy In data transfer in progress */
BAD_RESPONSE, /* an unexpected response was recv'd from the
* backend */
NONFATAL_ERROR, /* notice or warning message */
FATAL_ERROR, /* query failed */
COPY_BOTH, /* Copy In/Out data transfer in progress */
SINGLE_TUPLE, /* single tuple from larger resultset */
PIPELINE_SYNC, /* pipeline synchronization point */
PIPELINE_ABORTED, /* Command didn't run because of an abort
* earlier in a pipeline */
TUPLES_CHUNK /* chunk of tuples from larger resultset */
}

enum ColumnFormatCode : CInt
{
TEXT,
BINARY
}

enum Oid : int (int oid) {
BOOLOID = 16,
BYTEAOID = 17,
CHAROID = 18,
NAMEOID = 19,
INT8OID = 20,
INT2OID = 21,
INT2VECTOROID = 22,
INT4OID = 23,
REGPROCOID = 24,
TEXTOID = 25,
OIDOID = 26,
TIDOID = 27,
XIDOID = 28,
CIDOID = 29,
OIDVECTOROID = 30,
JSONOID = 114,
XMLOID = 142,
PG_NODE_TREEOID = 194,
PG_NDISTINCTOID = 3361,
PG_DEPENDENCIESOID = 3402,
PG_MCV_LISTOID = 5017,
PG_DDL_COMMANDOID = 32,
XID8OID = 5069,
POINTOID = 600,
LSEGOID = 601,
PATHOID = 602,
BOXOID = 603,
POLYGONOID = 604,
LINEOID = 628,
FLOAT4OID = 700,
FLOAT8OID = 701,
UNKNOWNOID = 705,
CIRCLEOID = 718,
MONEYOID = 790,
MACADDROID = 829,
INETOID = 869,
CIDROID = 650,
MACADDR8OID = 774,
ACLITEMOID = 1033,
BPCHAROID = 1042,
VARCHAROID = 1043,
DATEOID = 1082,
TIMEOID = 1083,
TIMESTAMPOID = 1114,
TIMESTAMPTZOID = 1184,
INTERVALOID = 1186,
TIMETZOID = 1266,
BITOID = 1560,
VARBITOID = 1562,
NUMERICOID = 1700,
REFCURSOROID = 1790,
REGPROCEDUREOID = 2202,
REGOPEROID = 2203,
REGOPERATOROID = 2204,
REGCLASSOID = 2205,
REGCOLLATIONOID = 4191,
REGTYPEOID = 2206,
REGROLEOID = 4096,
REGNAMESPACEOID = 4089,
UUIDOID = 2950,
PG_LSNOID = 3220,
TSVECTOROID = 3614,
GTSVECTOROID = 3642,
TSQUERYOID = 3615,
REGCONFIGOID = 3734,
REGDICTIONARYOID = 3769,
JSONBOID = 3802,
JSONPATHOID = 4072,
TXID_SNAPSHOTOID = 2970,
PG_SNAPSHOTOID = 5038,
INT4RANGEOID = 3904,
NUMRANGEOID = 3906,
TSRANGEOID = 3908,
TSTZRANGEOID = 3910,
DATERANGEOID = 3912,
INT8RANGEOID = 3926,
INT4MULTIRANGEOID = 4451,
NUMMULTIRANGEOID = 4532,
TSMULTIRANGEOID = 4533,
TSTZMULTIRANGEOID = 4534,
DATEMULTIRANGEOID = 4535,
INT8MULTIRANGEOID = 4536,
RECORDOID = 2249,
RECORDARRAYOID = 2287,
CSTRINGOID = 2275,
ANYOID = 2276,
ANYARRAYOID = 2277,
VOIDOID = 2278,
TRIGGEROID = 2279,
EVENT_TRIGGEROID = 3838,
LANGUAGE_HANDLEROID = 2280,
INTERNALOID = 2281,
ANYELEMENTOID = 2283,
ANYNONARRAYOID = 2776,
ANYENUMOID = 3500,
FDW_HANDLEROID = 3115,
INDEX_AM_HANDLEROID = 325,
TSM_HANDLEROID = 3310,
TABLE_AM_HANDLEROID = 269,
ANYRANGEOID = 3831,
ANYCOMPATIBLEOID = 5077,
ANYCOMPATIBLEARRAYOID = 5078,
ANYCOMPATIBLENONARRAYOID = 5079,
ANYCOMPATIBLERANGEOID = 5080,
ANYMULTIRANGEOID = 4537,
ANYCOMPATIBLEMULTIRANGEOID = 4538,
PG_BRIN_BLOOM_SUMMARYOID = 4600,
PG_BRIN_MINMAX_MULTI_SUMMARYOID = 4601,
BOOLARRAYOID = 1000,
BYTEAARRAYOID = 1001,
CHARARRAYOID = 1002,
NAMEARRAYOID = 1003,
INT8ARRAYOID = 1016,
INT2ARRAYOID = 1005,
INT2VECTORARRAYOID = 1006,
INT4ARRAYOID = 1007,
REGPROCARRAYOID = 1008,
TEXTARRAYOID = 1009,
OIDARRAYOID = 1028,
TIDARRAYOID = 1010,
XIDARRAYOID = 1011,
CIDARRAYOID = 1012,
OIDVECTORARRAYOID = 1013,
PG_TYPEARRAYOID = 210,
PG_ATTRIBUTEARRAYOID = 270,
PG_PROCARRAYOID = 272,
PG_CLASSARRAYOID = 273,
JSONARRAYOID = 199,
XMLARRAYOID = 143,
XID8ARRAYOID = 271,
POINTARRAYOID = 1017,
LSEGARRAYOID = 1018,
PATHARRAYOID = 1019,
BOXARRAYOID = 1020,
POLYGONARRAYOID = 1027,
LINEARRAYOID = 629,
FLOAT4ARRAYOID = 1021,
FLOAT8ARRAYOID = 1022,
CIRCLEARRAYOID = 719,
MONEYARRAYOID = 791,
MACADDRARRAYOID = 1040,
INETARRAYOID = 1041,
CIDRARRAYOID = 651,
MACADDR8ARRAYOID = 775,
ACLITEMARRAYOID = 1034,
BPCHARARRAYOID = 1014,
VARCHARARRAYOID = 1015,
DATEARRAYOID = 1182,
TIMEARRAYOID = 1183,
TIMESTAMPARRAYOID = 1115,
TIMESTAMPTZARRAYOID = 1185,
INTERVALARRAYOID = 1187,
TIMETZARRAYOID = 1270,
BITARRAYOID = 1561,
VARBITARRAYOID = 1563,
NUMERICARRAYOID = 1231,
REFCURSORARRAYOID = 2201,
REGPROCEDUREARRAYOID = 2207,
REGOPERARRAYOID = 2208,
REGOPERATORARRAYOID = 2209,
REGCLASSARRAYOID = 2210,
REGCOLLATIONARRAYOID = 4192,
REGTYPEARRAYOID = 2211,
REGROLEARRAYOID = 4097,
REGNAMESPACEARRAYOID = 4090,
UUIDARRAYOID = 2951,
PG_LSNARRAYOID = 3221,
TSVECTORARRAYOID = 3643,
GTSVECTORARRAYOID = 3644,
TSQUERYARRAYOID = 3645,
REGCONFIGARRAYOID = 3735,
REGDICTIONARYARRAYOID = 3770,
JSONBARRAYOID = 3807,
JSONPATHARRAYOID = 4073,
TXID_SNAPSHOTARRAYOID = 2949,
PG_SNAPSHOTARRAYOID = 5039,
INT4RANGEARRAYOID = 3905,
NUMRANGEARRAYOID = 3907,
TSRANGEARRAYOID = 3909,
TSTZRANGEARRAYOID = 3911,
DATERANGEARRAYOID = 3913,
INT8RANGEARRAYOID = 3927,
INT4MULTIRANGEARRAYOID = 6150,
NUMMULTIRANGEARRAYOID = 6151,
TSMULTIRANGEARRAYOID = 6152,
TSTZMULTIRANGEARRAYOID = 6153,
DATEMULTIRANGEARRAYOID = 6155,
INT8MULTIRANGEARRAYOID = 6157,
CSTRINGARRAYOID = 1263
}



// Connection Control Functions

extern fn PGconn connectdb(ZString conninfo) @extern("PQconnectdb");
extern fn void finish(PGconn conn) @extern("PQfinish");

// Connection Status Functions

extern fn ZString db(PGconn conn) @extern("PQdb");
extern fn ZString user(PGconn conn) @extern("PQuser");
extern fn ZString pass(PGconn conn) @extern("PQpass");
extern fn ZString host(PGconn conn) @extern("PQhost");
extern fn ZString hostaddr(PGconn conn) @extern("PQhostaddr");
extern fn ZString port(PGconn conn) @extern("PQport");
extern fn ZString tty(PGconn conn) @extern("PQtty") @deprecated;
extern fn ZString options(PGconn conn) @extern("PQoptions");
extern fn ConnStatusType status(PGconn conn) @extern("PQstatus");
// TODO
extern fn CInt server_version(PGconn conn) @extern("PQserverVersion");
extern fn ZString error_message(PGconn conn) @extern("PQerrorMessage");
// TODO

// Command Execution Functions

extern fn PGresult exec(PGconn conn, ZString command) @extern("PQexec");
extern fn ExecStatusType result_status(PGresult res) @extern("PQresultStatus");
extern fn void clear(PGresult res) @extern("PQclear");
extern fn CInt ntuples(PGresult res) @extern("PQntuples");
extern fn CInt nfields(PGresult res) @extern("PQnfields");
extern fn ZString fname(PGresult res, CInt column_number) @extern("PQfname");
extern fn CInt fnumber(PGresult res, ZString column_name) @extern("PQfnumber");
extern fn ColumnFormatCode fformat(PGresult res, CInt column_number) @extern("PQfformat");
extern fn CInt ftype(PGresult res, CInt column_number) @extern("PQftype");
extern fn ZString getvalue(PGresult res, CInt row_number, CInt column_number) @extern("PQgetvalue");
extern fn bool getisnull(PGresult res, CInt row_number, CInt column_number) @extern("PQgetisnull");
extern fn ZString cmd_status(PGresult res) @extern("PQcmdStatus");
extern fn ZString cmd_tuples(PGresult res) @extern("PQcmdTuples");
extern fn ZString result_error_message(PGresult res) @extern("PQresultErrorMessage");
extern fn PGresult exec_params(PGconn conn,
ZString command,
CInt nParams,
CInt* paramTypes,
ZString* paramValues,
CInt* paramLengths,
CInt* paramFormats,
CInt resultFormat) @extern("PQexecParams");
// Miscellaneous Functions

extern fn CInt lib_version() @extern("PQlibVersion");

0 comments on commit 9f0815d

Please sign in to comment.