Git Product home page Git Product logo

php-src's Issues

Document words from nikic

Description

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(...);
}

sqlite::blobOpen

Description

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 ]] )

add mysql-specific warning count function

Description

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 */

Postgres has a special thing I don't understand.

Description

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."

PDOMysql subclass

Description

Your task, should you choose to accept it...

  1. Create a stub class for a PDOMysql class in the pdo_mysql directory, containing an class that just extends PDO.

  2. 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.

  3. 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;

  4. 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

  1. 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....

  2. 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.

  3. 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.

Sqlite constants to expose

Description

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 */

DB specific functions to move

Description

Postgres

pgsqlCopyFromArray
pgsqlCopyFromFile
pgsqlCopyToArray
pgsqlCopyToFile
pgsqlGetNotify
pgsqlGetPid
pgsqlLOBCreate
pgsqlLOBOpen
pgsqlLOBUnlink

SQLIte

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

todo list

Description

  1. Add PDOSqlite stub.

  2. Create PDOSqlite class.

2a. Check it exists.

  1. Create a PDO::connect function.

  2. Extract the code that is in PDO::__construct to be used elsewhere, probably.

  3. Detect whether PDO is connecting to SQLite.

  4. Return an PDOSqlite class if it is.

  5. Implement PDOSqlite::openBlob

  6. Create PDOPostgres ?

  7. Find Postgres specific methods.

  8. Make all relevant classes only registered if their corresponding driver is loaded?

Add PDOSQLIte extension dir

Description

e.g. extension_dir

extension_dir = SQLITE3G(extension_dir);
extension_dir_len = strlen(SQLITE3G(extension_dir));

PHP Version

asd

Operating System

asd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.