Defines | Functions

pg_fld.c File Reference

DB_POSTGRES :: Data field conversion and type checking functions. More...

#include "pg_fld.h"
#include "pg_con.h"
#include "pg_mod.h"
#include "../../lib/srdb2/db_drv.h"
#include "../../mem/mem.h"
#include "../../dprint.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for pg_fld.c:

Go to the source code of this file.

Defines

Functions


Detailed Description

Module: DB_POSTGRES :: the PostgreSQL driver for Kamailio

Definition in file pg_fld.c.


Define Documentation

#define PG_EPOCH_TIME   ((int64_t)946684800)

2000-01-01 00:00:00 +0000 as the value of time_t in UTC

Definition at line 54 of file pg_fld.c.


Function Documentation

int pg_check_fld2pg ( db_fld_t *  fld,
pg_type_t types 
)

The functions checks whether all db_fld fields in the last parameter are compatible with column types on the server, for conversion to postgres format.

Parameters:
fld An array of db_fld fields to be checked.
types An array used to map internal field types to Oids.
Return values:
0 on success
A negative number on error.

Definition at line 389 of file pg_fld.c.

References pg_type::oid, PG_BIT, PG_BOOL, PG_BPCHAR, PG_BYTE, PG_CHAR, pg_fld(), PG_FLOAT4, PG_FLOAT8, PG_INET, PG_INT2, PG_INT4, PG_INT8, pg_oid2name(), PG_TEXT, PG_TIMESTAMP, PG_TIMESTAMPTZ, PG_VARBIT, and PG_VARCHAR.

Referenced by check_types().

Here is the call graph for this function:

Here is the caller graph for this function:

int pg_check_pg2fld ( db_fld_t *  fld,
pg_type_t types 
)

The functions checks whether all db_fld fields in the last parameter are compatible with column types on the server, for conversion to interal DB format.

Parameters:
fld An array of db_fld fields to be checked.
types An array used to map internal field types to Oids.
Return values:
0 on success
A negative number on error.

Definition at line 505 of file pg_fld.c.

References pg_type::oid, PG_BIT, PG_BOOL, PG_BPCHAR, PG_BYTE, PG_CHAR, pg_fld(), PG_FLOAT4, PG_FLOAT8, PG_INET, PG_INT2, PG_INT4, PG_INT8, pg_oid2name(), PG_TEXT, PG_TIMESTAMP, PG_TIMESTAMPTZ, PG_VARBIT, and PG_VARCHAR.

Referenced by check_types().

Here is the call graph for this function:

Here is the caller graph for this function:

int pg_fld ( db_fld_t *  fld,
char *  table 
)

This function creates a new PostgreSQL specific payload structure and attaches the structure to the generic db_fld structure.

Parameters:
fld A generic db_fld structure to be exended.
table Name of the table on the server.
Returns:
0 on success, negative number on error.

Definition at line 69 of file pg_fld.c.

References pg_fld(), and pg_fld_free().

Referenced by pg_check_fld2pg(), pg_check_pg2fld(), pg_fld(), and pg_fld2pg().

Here is the call graph for this function:

Here is the caller graph for this function:

int pg_fld2pg ( struct pg_params *  dst,
int  off,
pg_type_t types,
db_fld_t *  src,
unsigned int  flags 
)

The function converts fields in SER db_fld format to parameters suitable for PostgreSQL API functions.

Parameters:
dst An array of pointers to values in PostgreSQL format. The function will store pointers to converted values there.
off offset
types A type conversion table.
src An array of db_fld fields to be converted.
flags Connection flags controlling how values are converted.
Todo:

Implement support for bit fields with size bigger than 32

Implement support for varbit properly to remove leading zeroes

Check if timezones are handled properly

Support for DB_NONE in pg_pg2fld and pg_check_pg2fld

local->UTC conversion (also check the SQL command in ser-oob)

Definition at line 267 of file pg_fld.c.

References pg_type::oid, PG_BIT, PG_BOOL, PG_BPCHAR, PG_BYTE, PG_CHAR, pg_fld(), PG_FLOAT4, PG_FLOAT8, PG_INET, PG_INT2, PG_INT4, PG_INT8, PG_TEXT, PG_TIMESTAMP, PG_TIMESTAMPTZ, PG_VARBIT, and PG_VARCHAR.

Referenced by pg_cmd_exec().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pg_fld_free ( db_fld_t *  fld,
struct pg_fld *  payload 
) [static]

This function frees all memory used by a pg_fld structure

Parameters:
fld Generic db_fld_t* structure being freed.
payload The postgresql extension structure to be freed

Definition at line 62 of file pg_fld.c.

Referenced by pg_fld().

Here is the caller graph for this function:

int pg_pg2fld ( db_fld_t *  dst,
PGresult *  src,
int  row,
pg_type_t types,
unsigned int  flags 
)

The function converts fields from PostgreSQL result (PGresult structure) into the internal format used in SER. The function converts one row at a time.

Parameters:
dst The destination array of db_fld fields to be filled with converted values.
src A PostgreSQL result structure to be converted into SER format.
row Number of the row to be converted.
types A type conversion table.
flags Connection flags controlling how values are converted.
Return values:
0 on success
A negative number on error.
Todo:
UTC->local conversion

Definition at line 794 of file pg_fld.c.

References PG_BIT, PG_BOOL, PG_BPCHAR, PG_BYTE, PG_CHAR, PG_FLOAT4, PG_FLOAT8, PG_INET, PG_INT2, PG_INT4, PG_INT8, PG_TEXT, PG_TIMESTAMP, PG_TIMESTAMPTZ, PG_VARBIT, and PG_VARCHAR.

Referenced by pg_cmd_next().

Here is the caller graph for this function: