-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdo_cfd1.c
128 lines (110 loc) · 2.86 KB
/
pdo_cfd1.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
/* pdo_cfd1 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_cfd1.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_cfd1_error(
pdo_dbh_t *dbh,
pdo_stmt_t *stmt,
int errcode,
const char *sqlstate,
const char *errmsg,
const char *file,
int line
){
pdo_cfd1_db_handle *handle = (pdo_cfd1_db_handle*) dbh->driver_data;
pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
// pdo_cfd1_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;
}
#include "pdo_cfd1_db_statement.c"
#include "pdo_cfd1_db.c"
PHP_RINIT_FUNCTION(pdo_cfd1)
{
return SUCCESS;
}
PHP_MINIT_FUNCTION(pdo_cfd1)
{
// REGISTER_INI_ENTRIES();
#if defined(ZTS) && defined(COMPILE_DL_PDO_CFD1)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return php_pdo_register_driver(&pdo_cfd1_driver);
}
PHP_MINFO_FUNCTION(pdo_cfd1)
{
php_info_print_table_start();
php_info_print_table_row(2, "CloudFlare D1 SQL support for PDO", "enabled");
php_info_print_table_row(2, "CloudFlare D1 SQL module detected",
EM_ASM_INT({ return typeof Module.cfd1 === 'object' && Object.keys(Module.cfd1).length }) ? "yes" : "no"
);
php_info_print_table_end();
// DISPLAY_INI_ENTRIES();
}
PHP_MSHUTDOWN_FUNCTION(pdo_cfd1)
{
// UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
zend_module_entry pdo_cfd1_module_entry = {
STANDARD_MODULE_HEADER,
"pdo_cfd1",
NULL, /* zend_function_entry */
PHP_MINIT(pdo_cfd1), /* PHP_MINIT - Module initialization */
PHP_MSHUTDOWN(pdo_cfd1), /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(pdo_cfd1), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(pdo_cfd1), /* PHP_MINFO - Module info */
PHP_PDO_CFD1_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PDO_CFD1
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(pdo_cfd1)
#endif