-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdo_pglite.c
135 lines (116 loc) · 3.08 KB
/
pdo_pglite.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* pdo_pglite extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/standard/php_var.h"
#include "../pdo/php_pdo_driver.h"
#include "php_pdo_pglite.h"
#include "zend_API.h"
#include "zend_types.h"
#include "zend_closures.h"
#include <emscripten.h>
#include "zend_hash.h"
#if PHP_MAJOR_VERSION >= 8
# include "zend_attributes.h"
#else
# include <stdbool.h>
#endif
/* For compatibility with older PHP versions */
#ifndef ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif
int pdo_pglite_error(
pdo_dbh_t *dbh,
pdo_stmt_t *stmt,
int errcode,
const char *sqlstate,
const char *errmsg,
const char *file,
int line
){
pdo_pglite_db_handle *handle = (pdo_pglite_db_handle*) dbh->driver_data;
pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
// pdo_pglite_error_info *einfo = &handle->einfo;
handle->einfo.errcode = errcode;
handle->einfo.file = file;
handle->einfo.line = line;
if(errmsg)
{
handle->einfo.errmsg = pestrdup(errmsg, dbh->is_persistent);
}
if(sqlstate)
{
handle->einfo.sqlstate = pestrdup(sqlstate, dbh->is_persistent);
}
if(sqlstate == NULL || strlen(sqlstate) >= sizeof(pdo_error_type))
{
strcpy(*pdo_err, "HY000");
}
else
{
strcpy(*pdo_err, sqlstate);
}
if(!dbh->methods)
{
pdo_throw_exception(handle->einfo.errcode, handle->einfo.errmsg, pdo_err);
}
return errcode;
}
// PHP_INI_BEGIN()
// PHP_INI_ENTRY("pdo_pglite.prefix", "pgsql", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
// PHP_INI_END()
#include "pdo_pglite_db_statement.c"
#include "pdo_pglite_db.c"
PHP_MINIT_FUNCTION(pdo_pglite)
{
// REGISTER_INI_ENTRIES();
#if defined(ZTS) && defined(COMPILE_DL_PDO_PGLITE)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
php_pdo_register_driver(&pdo_pglite_driver);
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(pdo_pglite)
{
php_pdo_unregister_driver(&pdo_pglite_driver);
// UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MINFO_FUNCTION(pdo_pglite)
{
php_info_print_table_start();
php_info_print_table_row(2, "PGlite support for PDO", "enabled");
php_info_print_table_row(2, "PGlite module detected",
EM_ASM_INT({ return !!Module.PGlite }) ? "yes" : "no"
);
php_info_print_table_end();
// DISPLAY_INI_ENTRIES();
}
static const zend_module_dep pdo_pglite_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
zend_module_entry pdo_pglite_module_entry = {
STANDARD_MODULE_HEADER_EX, NULL,
pdo_pglite_deps,
"pdo_pglite",
NULL, /* zend_function_entry */
PHP_MINIT(pdo_pglite), /* PHP_MINIT - Module initialization */
PHP_MSHUTDOWN(pdo_pglite), /* PHP_MSHUTDOWN - Module shutdown */
NULL, /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(pdo_pglite), /* PHP_MINFO - Module info */
PHP_PDO_PGLITE_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PDO_PGLITE
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(pdo_pglite)
#endif