xref: /PHP-8.4/ext/pdo_firebird/pdo_firebird.c (revision c550d341)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Author: Ard Biesheuvel <abies@php.net>                               |
14   +----------------------------------------------------------------------+
15 */
16 
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20 
21 #include "php.h"
22 #include "php_ini.h"
23 #include "ext/standard/info.h"
24 #include "ext/pdo/php_pdo.h"
25 #include "ext/pdo/php_pdo_driver.h"
26 #include "php_pdo_firebird.h"
27 #include "php_pdo_firebird_int.h"
28 #include "pdo_firebird_arginfo.h"
29 
30 static zend_class_entry *PdoFirebird_ce;
31 
32 /* {{{ pdo_firebird_deps */
33 static const zend_module_dep pdo_firebird_deps[] = {
34 	ZEND_MOD_REQUIRED("pdo")
35 	ZEND_MOD_END
36 };
37 /* }}} */
38 
39 zend_module_entry pdo_firebird_module_entry = { /* {{{ */
40 	STANDARD_MODULE_HEADER_EX, NULL,
41 	pdo_firebird_deps,
42 	"PDO_Firebird",
43 	NULL,
44 	PHP_MINIT(pdo_firebird),
45 	PHP_MSHUTDOWN(pdo_firebird),
46 	NULL,
47 	NULL,
48 	PHP_MINFO(pdo_firebird),
49 	PHP_PDO_FIREBIRD_VERSION,
50 	STANDARD_MODULE_PROPERTIES
51 };
52 /* }}} */
53 
54 #ifdef COMPILE_DL_PDO_FIREBIRD
55 ZEND_GET_MODULE(pdo_firebird)
56 #endif
57 
PHP_MINIT_FUNCTION(pdo_firebird)58 PHP_MINIT_FUNCTION(pdo_firebird) /* {{{ */
59 {
60 	REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_DATE_FORMAT", (zend_long) PDO_FB_ATTR_DATE_FORMAT);
61 	REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_TIME_FORMAT", (zend_long) PDO_FB_ATTR_TIME_FORMAT);
62 	REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_TIMESTAMP_FORMAT", (zend_long) PDO_FB_ATTR_TIMESTAMP_FORMAT);
63 
64 	if (FAILURE == php_pdo_register_driver(&pdo_firebird_driver)) {
65 		return FAILURE;
66 	}
67 
68 	PdoFirebird_ce = register_class_Pdo_Firebird(pdo_dbh_ce);
69 	PdoFirebird_ce->create_object = pdo_dbh_new;
70 
71 #ifdef ZEND_SIGNALS
72 	/* firebird replaces some signals at runtime, suppress warnings. */
73 	SIGG(check) = 0;
74 #endif
75 
76 	return php_pdo_register_driver_specific_ce(&pdo_firebird_driver, PdoFirebird_ce);
77 }
78 /* }}} */
79 
PHP_MSHUTDOWN_FUNCTION(pdo_firebird)80 PHP_MSHUTDOWN_FUNCTION(pdo_firebird) /* {{{ */
81 {
82 	php_pdo_unregister_driver(&pdo_firebird_driver);
83 
84 	return SUCCESS;
85 }
86 /* }}} */
87 
PHP_MINFO_FUNCTION(pdo_firebird)88 PHP_MINFO_FUNCTION(pdo_firebird) /* {{{ */
89 {
90 	char version[64];
91 	char api_version[8];
92 	isc_get_client_version(version);
93 
94 	snprintf(api_version, 7, "%d", FB_API_VER);
95 
96 	php_info_print_table_start();
97 	php_info_print_table_row(2, "PDO Driver for Firebird", "enabled");
98 	php_info_print_table_row(2, "Client Library Version", version);
99 	php_info_print_table_row(2, "Firebird API version", api_version);
100 	php_info_print_table_end();
101 }
102 /* }}} */
103 
PHP_METHOD(Pdo_Firebird,getApiVersion)104 PHP_METHOD(Pdo_Firebird, getApiVersion)
105 {
106 	if (zend_parse_parameters_none() == FAILURE) {
107 		RETURN_THROWS();
108 	}
109 
110 	RETURN_LONG(FB_API_VER);
111 }
112