#undef PHP_PQ_TYPE
#include "php_pq_type.h"
+/* convert version to string */
+extern void php_pq_version_to_string(int version, char *buffer, int len) {
+ if (version < 100000) {
+ slprintf(buffer, len, "%d.%d.%d", version/10000, version/100%100, version%100);
+ } else { /* since version 10 */
+ slprintf(buffer, len, "%d.%d", version/10000, version%100);
+ }
+}
/* clear result object associated with a result handle */
void php_pqres_clear(PGresult *r) {
extern PGresult *php_pq_prepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes);
extern PGresult *php_pq_exec_prepared(PGconn *conn, const char *stmtName, int nParams, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat);
+/* convert version to string */
+extern void php_pq_version_to_string(int version, char *buffer, int len);
/* trim LF from EOL */
extern char *php_pq_rtrim(char *e);
php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
#ifdef HAVE_PQLIBVERSION
libpq_v = PQlibVersion();
- if (libpq_v < 100000) {
- slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000, libpq_v/100%100, libpq_v%100);
- } else {
- slprintf(libpq_version, sizeof(libpq_version), "%d.%d", libpq_v/10000, libpq_v%100);
- }
+ php_pq_version_to_string(libpq_v, libpq_version, sizeof(libpq_version));
#endif
php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version);
php_info_print_table_end();
static void php_pqconn_object_read_lib_version(void *o, zval *return_value)
{
char ver[16];
- int v = PQlibVersion();
- if (v < 100000) {
- slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100);
- } else {
- slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100);
- }
+ php_pq_version_to_string(PQlibVersion(), ver, sizeof(ver));
RETVAL_STRING(ver);
}
#endif
{
php_pqconn_object_t *obj = o;
char ver[16];
- int v = PQserverVersion(obj->intern->conn);
- if (v < 100000) {
- slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100);
- } else {
- slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100);
- }
+ php_pq_version_to_string(PQserverVersion(obj->intern->conn), ver, sizeof(ver));
RETVAL_STRING(ver);
}
#endif