diff --git a/agent/php_internal_instrument.c b/agent/php_internal_instrument.c index ce6c089ec..e37510e32 100644 --- a/agent/php_internal_instrument.c +++ b/agent/php_internal_instrument.c @@ -3840,9 +3840,37 @@ void nr_php_generate_internal_wrap_records(void) { NR_INTERNAL_WRAPREC("sqlite3::exec", sqlite3_exec, sqlite3, 0, 0) NR_INTERNAL_WRAPREC("pdo::__construct", pdo_construct, pdo_construct, 0, 0) +#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO + NR_INTERNAL_WRAPREC("pdo\\firebird::__construct", pdo_construct, pdo_construct, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\mysql::__construct", pdo_construct, pdo_construct, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\odbc::__construct", pdo_construct, pdo_construct, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\pgsql::__construct", pdo_construct, pdo_construct, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\sqlite::__construct", pdo_construct, pdo_construct, 0, 0) +#endif NR_INTERNAL_WRAPREC("pdo::query", pdo_query, pdo_query, 0, 0) +#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO + NR_INTERNAL_WRAPREC("pdo\\firebird::query", pdo_query, pdo_query, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\mysql::query", pdo_query, pdo_query, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\odbc::query", pdo_query, pdo_query, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\pgsql::query", pdo_query, pdo_query, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\sqlite::query", pdo_query, pdo_query, 0, 0) +#endif NR_INTERNAL_WRAPREC("pdo::exec", pdo_exec, pdo_exec, 0, 0) +#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO + NR_INTERNAL_WRAPREC("pdo\\firebird::exec", pdo_exec, pdo_exec, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\mysql::exec", pdo_exec, pdo_exec, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\odbc::exec", pdo_exec, pdo_exec, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\pgsql::exec", pdo_exec, pdo_exec, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\sqlite::exec", pdo_exec, pdo_exec, 0, 0) +#endif NR_INTERNAL_WRAPREC("pdo::prepare", pdo_prepare, pdo_prepare, 0, 0) +#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO + NR_INTERNAL_WRAPREC("pdo\\firebird::prepare", pdo_prepare, pdo_prepare, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\mysql::prepare", pdo_prepare, pdo_prepare, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\odbc::prepare", pdo_prepare, pdo_prepare, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\pgsql::prepare", pdo_prepare, pdo_prepare, 0, 0) + NR_INTERNAL_WRAPREC("pdo\\sqlite::prepare", pdo_prepare, pdo_prepare, 0, 0) +#endif NR_INTERNAL_WRAPREC("pdostatement::execute", pdostmt_execute, pdostatement_execute, 0, 0) diff --git a/files/Dockerfile b/files/Dockerfile index 93ae60942..2f99740e3 100644 --- a/files/Dockerfile +++ b/files/Dockerfile @@ -89,7 +89,7 @@ COPY --from=composer ["/usr/bin/composer", "/usr/bin/composer"] # and 8.0 has problems with how the explanation for informational_schema # work (refer to bug https://bugs.mysql.com/bug.php?id=102536) so to run # the mysql tests a separate machine running mysql server 5.6 is required. -RUN docker-php-ext-install pdo pdo_mysql +RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql # install redis extension required by test_redis: RUN \ diff --git a/tests/include/config.php b/tests/include/config.php index 4cde7cfb2..399d15552 100644 --- a/tests/include/config.php +++ b/tests/include/config.php @@ -13,7 +13,7 @@ function isset_or($check, $alternate = NULL) $MYSQL_USER = isset_or('MYSQL_USER', 'root'); $MYSQL_PASSWD = isset_or('MYSQL_PASSWD', 'root'); -$MYSQL_DB = 'information_schema'; // TODO: MSL comment here. +$MYSQL_DB = isset_or('MYSQL_DB', 'information_schema'); $MYSQL_HOST = isset_or('MYSQL_HOST', 'localhost'); $MYSQL_PORT = isset_or('MYSQL_PORT', 3306); $MYSQL_SOCKET = isset_or('MYSQL_SOCKET', ''); @@ -75,6 +75,10 @@ function make_tracing_url($file) $PG_PORT = isset_or('PG_PORT', '5433'); $PG_CONNECTION = "host=$PG_HOST port=$PG_PORT user=$PG_USER password=$PG_PW connect_timeout=1"; +$PDO_PGSQL_DSN = 'pgsql:'; +$PDO_PGSQL_DSN .= 'host=' . $PG_HOST . ';'; +$PDO_PGSQL_DSN .= 'port=' . $PG_PORT . ';'; + // Header used to track whether or not our CAT instrumentation interferes with // other existing headers. define('CUSTOMER_HEADER', 'Customer-Header'); diff --git a/tests/integration/events/test_database_duration.php b/tests/integration/events/test_database_duration.php index a9c242dac..b329127f8 100644 --- a/tests/integration/events/test_database_duration.php +++ b/tests/integration/events/test_database_duration.php @@ -49,7 +49,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/mysql/base-class/test_instance_reporting_port.php b/tests/integration/pdo/mysql/base-class/test_instance_reporting_port.php new file mode 100644 index 000000000..0742b5461 --- /dev/null +++ b/tests/integration/pdo/mysql/base-class/test_instance_reporting_port.php @@ -0,0 +1,157 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/base-class/test_instance_reporting_socket.php b/tests/integration/pdo/mysql/base-class/test_instance_reporting_socket.php new file mode 100644 index 000000000..95177d7c7 --- /dev/null +++ b/tests/integration/pdo/mysql/base-class/test_instance_reporting_socket.php @@ -0,0 +1,160 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$DSN = 'mysql:'; +$DSN .= 'unix_socket=' . $MYSQL_SOCKET . ';'; +$DSN .= 'dbname=' . $MYSQL_DB . ';'; + +test_instance_reporting(new PDO($DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/base-class/test_prepared_stmt_basic.php b/tests/integration/pdo/mysql/base-class/test_prepared_stmt_basic.php new file mode 100644 index 000000000..93e54a033 --- /dev/null +++ b/tests/integration/pdo/mysql/base-class/test_prepared_stmt_basic.php @@ -0,0 +1,110 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/base-class/test_prepared_stmt_bind_value.php b/tests/integration/pdo/mysql/base-class/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..34868e9ec --- /dev/null +++ b/tests/integration/pdo/mysql/base-class/test_prepared_stmt_bind_value.php @@ -0,0 +1,111 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/base-class/test_query_1_arg.php b/tests/integration/pdo/mysql/base-class/test_query_1_arg.php new file mode 100644 index 000000000..65a1da4fa --- /dev/null +++ b/tests/integration/pdo/mysql/base-class/test_query_1_arg.php @@ -0,0 +1,52 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(new Pdo\Mysql($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/constructor/test_instance_reporting_socket.php b/tests/integration/pdo/mysql/constructor/test_instance_reporting_socket.php new file mode 100644 index 000000000..073bceb80 --- /dev/null +++ b/tests/integration/pdo/mysql/constructor/test_instance_reporting_socket.php @@ -0,0 +1,161 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$DSN = 'mysql:'; +$DSN .= 'unix_socket=' . $MYSQL_SOCKET . ';'; +$DSN .= 'dbname=' . $MYSQL_DB . ';'; + +test_instance_reporting(new Pdo\Mysql($DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/constructor/test_prepared_stmt_basic.php b/tests/integration/pdo/mysql/constructor/test_prepared_stmt_basic.php new file mode 100644 index 000000000..695dab225 --- /dev/null +++ b/tests/integration/pdo/mysql/constructor/test_prepared_stmt_basic.php @@ -0,0 +1,111 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(new Pdo\Mysql($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/constructor/test_prepared_stmt_bind_value.php b/tests/integration/pdo/mysql/constructor/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..214533332 --- /dev/null +++ b/tests/integration/pdo/mysql/constructor/test_prepared_stmt_bind_value.php @@ -0,0 +1,112 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(new Pdo\Mysql($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/constructor/test_query_1_arg.php b/tests/integration/pdo/mysql/constructor/test_query_1_arg.php new file mode 100644 index 000000000..63d641e70 --- /dev/null +++ b/tests/integration/pdo/mysql/constructor/test_query_1_arg.php @@ -0,0 +1,53 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[MYSQL_HOST]", + "port_path_or_id": "ENV[MYSQL_PORT]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[MYSQL_HOST]", + "peer.address": "ENV[MYSQL_HOST]:ENV[MYSQL_PORT]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(PDO::connect($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/factory/test_instance_reporting_socket.php b/tests/integration/pdo/mysql/factory/test_instance_reporting_socket.php new file mode 100644 index 000000000..796d108db --- /dev/null +++ b/tests/integration/pdo/mysql/factory/test_instance_reporting_socket.php @@ -0,0 +1,161 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "__HOST__", + "port_path_or_id": "ENV[MYSQL_SOCKET]", + "database_name": "ENV[MYSQL_DB]" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "__HOST__", + "peer.address": "__HOST__:ENV[MYSQL_SOCKET]", + "db.instance": "ENV[MYSQL_DB]", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$DSN = 'mysql:'; +$DSN .= 'unix_socket=' . $MYSQL_SOCKET . ';'; +$DSN .= 'dbname=' . $MYSQL_DB . ';'; + +test_instance_reporting(PDO::connect($DSN, $MYSQL_USER, $MYSQL_PASSWD), 0); diff --git a/tests/integration/pdo/mysql/factory/test_prepared_stmt_basic.php b/tests/integration/pdo/mysql/factory/test_prepared_stmt_basic.php new file mode 100644 index 000000000..6488f0ffe --- /dev/null +++ b/tests/integration/pdo/mysql/factory/test_prepared_stmt_basic.php @@ -0,0 +1,111 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(PDO::connect($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/factory/test_prepared_stmt_bind_value.php b/tests/integration/pdo/mysql/factory/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..e1cae652e --- /dev/null +++ b/tests/integration/pdo/mysql/factory/test_prepared_stmt_bind_value.php @@ -0,0 +1,112 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ], + "explain_plan": "??" + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(PDO::connect($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD), $query); diff --git a/tests/integration/pdo/mysql/factory/test_query_1_arg.php b/tests/integration/pdo/mysql/factory/test_query_1_arg.php new file mode 100644 index 000000000..b15999e0b --- /dev/null +++ b/tests/integration/pdo/mysql/factory/test_query_1_arg.php @@ -0,0 +1,53 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(new PDO($PDO_PGSQL_DSN, $PG_USER, $PG_PW), 0); diff --git a/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_basic.php b/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_basic.php new file mode 100644 index 000000000..9c7960080 --- /dev/null +++ b/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_basic.php @@ -0,0 +1,106 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(new PDO($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_bind_value.php b/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..56737cafb --- /dev/null +++ b/tests/integration/pdo/pgsql/base-class/test_prepared_stmt_bind_value.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(new PDO($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/base-class/test_query_1_arg.php b/tests/integration/pdo/pgsql/base-class/test_query_1_arg.php new file mode 100644 index 000000000..48e212208 --- /dev/null +++ b/tests/integration/pdo/pgsql/base-class/test_query_1_arg.php @@ -0,0 +1,55 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(new Pdo\Pgsql($PDO_PGSQL_DSN, $PG_USER, $PG_PW), 0); diff --git a/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_basic.php b/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_basic.php new file mode 100644 index 000000000..131ab0935 --- /dev/null +++ b/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_basic.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(new Pdo\Pgsql($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_bind_value.php b/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..c954060f8 --- /dev/null +++ b/tests/integration/pdo/pgsql/constructor/test_prepared_stmt_bind_value.php @@ -0,0 +1,108 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(new Pdo\Pgsql($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/constructor/test_query_1_arg.php b/tests/integration/pdo/pgsql/constructor/test_query_1_arg.php new file mode 100644 index 000000000..c3cc9381d --- /dev/null +++ b/tests/integration/pdo/pgsql/constructor/test_query_1_arg.php @@ -0,0 +1,52 @@ +", + "?? SQL id", + "DROP TABLE ENV[DATASTORE_COLLECTION];", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ], + [ + "OtherTransaction/php__FILE__", + "", + "?? SQL id", + "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDO::exec called at .*\/", + " in test_instance_reporting called at __FILE__ (??)" + ], + "host": "ENV[PG_HOST]", + "port_path_or_id": "ENV[PG_PORT]", + "database_name": "postgres" + } + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/create", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "CREATE TABLE ENV[DATASTORE_COLLECTION] (id INT, description VARCHAR(?));" + } + ], + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/drop", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.hostname": "ENV[PG_HOST]", + "peer.address": "ENV[PG_HOST]:ENV[PG_PORT]", + "db.instance": "postgres", + "db.statement": "DROP TABLE ENV[DATASTORE_COLLECTION];" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_instance_reporting.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +test_instance_reporting(PDO::connect($PDO_PGSQL_DSN, $PG_USER, $PG_PW), 0); diff --git a/tests/integration/pdo/pgsql/factory/test_prepared_stmt_basic.php b/tests/integration/pdo/pgsql/factory/test_prepared_stmt_basic.php new file mode 100644 index 000000000..58841fbf7 --- /dev/null +++ b/tests/integration/pdo/pgsql/factory/test_prepared_stmt_basic.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from information_schema.tables limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables limit 1;'; +test_prepared_stmt(PDO::connect($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/factory/test_prepared_stmt_bind_value.php b/tests/integration/pdo/pgsql/factory/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..7ccfa9e9f --- /dev/null +++ b/tests/integration/pdo/pgsql/factory/test_prepared_stmt_bind_value.php @@ -0,0 +1,108 @@ +", + "?? SQL id", + "select * from information_schema.tables where table_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from information_schema.tables where table_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from information_schema.tables where table_name = ? limit 1;'; +test_prepared_stmt(PDO::connect($PDO_PGSQL_DSN, $PG_USER, $PG_PW), $query); diff --git a/tests/integration/pdo/pgsql/factory/test_query_1_arg.php b/tests/integration/pdo/pgsql/factory/test_query_1_arg.php new file mode 100644 index 000000000..1f47b55b7 --- /dev/null +++ b/tests/integration/pdo/pgsql/factory/test_query_1_arg.php @@ -0,0 +1,52 @@ += 8.4\n"); +} + diff --git a/tests/integration/pdo/skipif_pgsql.inc b/tests/integration/pdo/skipif_pgsql.inc new file mode 100644 index 000000000..92caf44be --- /dev/null +++ b/tests/integration/pdo/skipif_pgsql.inc @@ -0,0 +1,37 @@ +getMessage() . "\n"); +} diff --git a/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_basic.php b/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_basic.php new file mode 100644 index 000000000..ddf000ce8 --- /dev/null +++ b/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_basic.php @@ -0,0 +1,106 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_master limit 1;'; +test_prepared_stmt(new PDO('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_bind_value.php b/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..a26e0802f --- /dev/null +++ b/tests/integration/pdo/sqlite/base-class/test_prepared_stmt_bind_value.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_master where tbl_name = ? limit 1;'; +test_prepared_stmt(new PDO('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/test_query_1.php b/tests/integration/pdo/sqlite/base-class/test_query_1_arg.php similarity index 76% rename from tests/integration/pdo/test_query_1.php rename to tests/integration/pdo/sqlite/base-class/test_query_1_arg.php index 21b932f49..df16dc8a3 100644 --- a/tests/integration/pdo/test_query_1.php +++ b/tests/integration/pdo/sqlite/base-class/test_query_1_arg.php @@ -6,14 +6,12 @@ /*DESCRIPTION The agent should record Datastore metrics for the one argument form of -PDO::query(). +PDO::query() when PDO base class constructor is used to create connection +object. */ /*SKIPIF -=")) { - die("skip: PHP >= 8.1.0 not supported\n"); -} +exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); - - $expected = array( - array('id' => '1', 'desc' => 'one'), - array('id' => '2', 'desc' => 'two'), - array('id' => '3', 'desc' => 'three') - ); - - $result = $conn->query('SELECT * FROM test;'); - $actual = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - tap_equal($expected, $actual, 'query (1-arg)'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); -} - -test_pdo_query(); +test_pdo_query(new PDO('sqlite::memory:')); diff --git a/tests/integration/pdo/test_query_3.php b/tests/integration/pdo/sqlite/base-class/test_query_fetch_class.php similarity index 82% rename from tests/integration/pdo/test_query_3.php rename to tests/integration/pdo/sqlite/base-class/test_query_fetch_class.php index e37919a72..e84fb4027 100644 --- a/tests/integration/pdo/test_query_3.php +++ b/tests/integration/pdo/sqlite/base-class/test_query_fetch_class.php @@ -6,11 +6,12 @@ /*DESCRIPTION The agent should record database metrics for the FETCH_CLASS variant of -PDO::query(). +PDO::query() when PDO base class constructor is used to create connection +object. */ /*SKIPIF -exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert row'); - - $expected = new Row(); - $expected->id = '1'; - $expected->desc = 'one'; - - $actual = $conn->query('SELECT * FROM test;', PDO::FETCH_CLASS, 'Row')->fetch(); - tap_assert($expected == $actual, 'fetch row as object'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); -} - -test_pdo_query(); +test_pdo_query(new PDO('sqlite::memory:')); diff --git a/tests/integration/pdo/test_query_2.php b/tests/integration/pdo/sqlite/base-class/test_query_fetch_column.php similarity index 81% rename from tests/integration/pdo/test_query_2.php rename to tests/integration/pdo/sqlite/base-class/test_query_fetch_column.php index e0269144c..37989527d 100644 --- a/tests/integration/pdo/test_query_2.php +++ b/tests/integration/pdo/sqlite/base-class/test_query_fetch_column.php @@ -6,11 +6,12 @@ /*DESCRIPTION The agent should record database metrics for the FETCH_COLUMN variant of -PDO::query(). +PDO::query() when PDO base class constructor is used to create connection +object. */ /*SKIPIF -exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); - - $result = $conn->query('SELECT * FROM test;', PDO::FETCH_COLUMN, 1); - $actual = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - tap_equal(3, count($actual), 'fetch column'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); -} - -test_pdo_query(); +test_pdo_query(new PDO('sqlite::memory:')); diff --git a/tests/integration/pdo/test_query_2_logging_off.php b/tests/integration/pdo/sqlite/base-class/test_query_fetch_column_logging_off.php similarity index 81% rename from tests/integration/pdo/test_query_2_logging_off.php rename to tests/integration/pdo/sqlite/base-class/test_query_fetch_column_logging_off.php index f3d2da948..76a35f1fc 100644 --- a/tests/integration/pdo/test_query_2_logging_off.php +++ b/tests/integration/pdo/sqlite/base-class/test_query_fetch_column_logging_off.php @@ -6,11 +6,12 @@ /*DESCRIPTION The agent should record database metrics for the FETCH_COLUMN variant of -PDO::query(). +PDO::query() when PDO base class constructor is used to create connection +object. */ /*SKIPIF -exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); - - $result = $conn->query('SELECT * FROM test;', PDO::FETCH_COLUMN, 1); - $actual = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - tap_equal(3, count($actual), 'fetch column'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); -} - -test_pdo_query(); +test_pdo_query(new PDO('sqlite::memory:')); diff --git a/tests/integration/pdo/test_query_4.php b/tests/integration/pdo/sqlite/base-class/test_query_fetch_into.php similarity index 82% rename from tests/integration/pdo/test_query_4.php rename to tests/integration/pdo/sqlite/base-class/test_query_fetch_into.php index 884bb1f8d..63c132317 100644 --- a/tests/integration/pdo/test_query_4.php +++ b/tests/integration/pdo/sqlite/base-class/test_query_fetch_into.php @@ -6,11 +6,12 @@ /*DESCRIPTION The agent should record database metrics for the FETCH_INTO variant of -PDO::query(). +PDO::query() when PDO base class constructor is used to create connection +object. */ /*SKIPIF -exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert row'); - - $expected = new Row(); - $expected->id = '1'; - $expected->desc = 'one'; - - $actual = new Row(); - $conn->query('SELECT * FROM test;', PDO::FETCH_INTO, $actual)->fetch(); - tap_assert($expected == $actual, 'fetch row into object'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); -} - -test_pdo_query(); +test_pdo_query(new PDO('sqlite::memory:')); diff --git a/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_basic.php b/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_basic.php new file mode 100644 index 000000000..bdb32dd76 --- /dev/null +++ b/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_basic.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_schema limit 1;'; +test_prepared_stmt(new Pdo\Sqlite('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_bind_value.php b/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..36e02cb5e --- /dev/null +++ b/tests/integration/pdo/sqlite/constructor/test_prepared_stmt_bind_value.php @@ -0,0 +1,108 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_schema where tbl_name = ? limit 1;'; +test_prepared_stmt(new Pdo\Sqlite('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/sqlite/constructor/test_query_1_arg.php b/tests/integration/pdo/sqlite/constructor/test_query_1_arg.php new file mode 100644 index 000000000..d0dc104cf --- /dev/null +++ b/tests/integration/pdo/sqlite/constructor/test_query_1_arg.php @@ -0,0 +1,75 @@ +exec("CREATE TABLE test (id INT, desc VARCHAR(10));"), 'create table'); - - tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); - tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); - - $expected = array( - array('id' => 1, 'desc' => 'one'), - array('id' => 2, 'desc' => 'two'), - array('id' => 3, 'desc' => 'three') - ); - - $result = $conn->query('SELECT * FROM test;'); - $actual = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - tap_equal($expected, $actual, 'query (1-arg)'); - - tap_equal(1, $conn->exec("DROP TABLE test;"), 'drop table'); +class MyPDO extends \PDO +{ } -test_pdo_query(); +test_pdo_query(new MyPDO('sqlite::memory:')); diff --git a/tests/integration/pdo/sqlite/factory/test_prepared_stmt_basic.php b/tests/integration/pdo/sqlite/factory/test_prepared_stmt_basic.php new file mode 100644 index 000000000..652f65165 --- /dev/null +++ b/tests/integration/pdo/sqlite/factory/test_prepared_stmt_basic.php @@ -0,0 +1,107 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_basic.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_schema limit 1;'; +test_prepared_stmt(PDO::Connect('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/sqlite/factory/test_prepared_stmt_bind_value.php b/tests/integration/pdo/sqlite/factory/test_prepared_stmt_bind_value.php new file mode 100644 index 000000000..c4c548970 --- /dev/null +++ b/tests/integration/pdo/sqlite/factory/test_prepared_stmt_bind_value.php @@ -0,0 +1,108 @@ +", + "?? SQL id", + "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;", + "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + 1, + "?? total time", + "?? min time", + "?? max time", + { + "backtrace": [ + "/ in PDOStatement::execute called at .*\/", + " in test_prepared_stmt called at __FILE__ (??)" + ] + } + ] + ] +] +*/ + +// peer.address is unknown:unknown because instance_reporting is disabled +/*EXPECT_SPAN_EVENTS_LIKE +[ + [ + { + "category": "datastore", + "type": "Span", + "guid": "??", + "traceId": "??", + "transactionId": "??", + "name": "Datastore/statement/ENV[DATASTORE_PRODUCT]/ENV[DATASTORE_COLLECTION]/select", + "timestamp": "??", + "duration": "??", + "priority": "??", + "sampled": true, + "parentId": "??", + "span.kind": "client", + "component": "ENV[DATASTORE_PRODUCT]" + }, + {}, + { + "peer.address": "unknown:unknown", + "db.statement": "select * from ENV[DATASTORE_COLLECTION] where tbl_name = ? limit ?;" + } + ] +] +*/ + +require_once(realpath (dirname ( __FILE__ )) . '/../../test_prepared_stmt_bind_value.inc'); +require_once(realpath (dirname ( __FILE__ )) . '/../../../../include/config.php'); + +$query = 'select * from sqlite_schema where tbl_name = ? limit 1;'; +test_prepared_stmt(PDO::Connect('sqlite::memory:'), $query); diff --git a/tests/integration/pdo/sqlite/factory/test_query_1_arg.php b/tests/integration/pdo/sqlite/factory/test_query_1_arg.php new file mode 100644 index 000000000..edab45185 --- /dev/null +++ b/tests/integration/pdo/sqlite/factory/test_query_1_arg.php @@ -0,0 +1,75 @@ +", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -85,7 +85,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_empty_driver_options.php81.php b/tests/integration/pdo/test_empty_driver_options.php81.php index 60f3e3778..e29984f62 100644 --- a/tests/integration/pdo/test_empty_driver_options.php81.php +++ b/tests/integration/pdo/test_empty_driver_options.php81.php @@ -32,7 +32,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -85,7 +85,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_instance_reporting.inc b/tests/integration/pdo/test_instance_reporting.inc new file mode 100644 index 000000000..0ae7fb6a8 --- /dev/null +++ b/tests/integration/pdo/test_instance_reporting.inc @@ -0,0 +1,33 @@ +exec("CREATE TABLE test (id INT, description VARCHAR(10));"), 'create table'); + tap_equal($want_drop_table_result, $conn->exec("DROP TABLE test;"), 'drop table'); +} diff --git a/tests/integration/pdo/test_instance_slow_sql_1.php b/tests/integration/pdo/test_instance_slow_sql_1.php index 465ab00a1..b767100ba 100644 --- a/tests/integration/pdo/test_instance_slow_sql_1.php +++ b/tests/integration/pdo/test_instance_slow_sql_1.php @@ -45,7 +45,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -103,7 +103,7 @@ function test_query() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_query(); diff --git a/tests/integration/pdo/test_instance_slow_sql_1.php81.php b/tests/integration/pdo/test_instance_slow_sql_1.php81.php index 80a890f2e..1d217e04f 100644 --- a/tests/integration/pdo/test_instance_slow_sql_1.php81.php +++ b/tests/integration/pdo/test_instance_slow_sql_1.php81.php @@ -41,7 +41,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -99,7 +99,7 @@ function test_query() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_query(); diff --git a/tests/integration/pdo/test_instance_slow_sql_2.php b/tests/integration/pdo/test_instance_slow_sql_2.php index afa7e5df6..47330ea78 100644 --- a/tests/integration/pdo/test_instance_slow_sql_2.php +++ b/tests/integration/pdo/test_instance_slow_sql_2.php @@ -40,7 +40,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -98,7 +98,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables limit 1;'); tap_assert($stmt->execute(), 'execute slow query'); } diff --git a/tests/integration/pdo/test_instance_slow_sql_2.php81.php b/tests/integration/pdo/test_instance_slow_sql_2.php81.php index 60e833f34..9a7767cf0 100644 --- a/tests/integration/pdo/test_instance_slow_sql_2.php81.php +++ b/tests/integration/pdo/test_instance_slow_sql_2.php81.php @@ -40,7 +40,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -98,7 +98,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables limit 1;'); tap_assert($stmt->execute(), 'execute slow query'); } diff --git a/tests/integration/pdo/test_instance_slow_sql_for_update.php b/tests/integration/pdo/test_instance_slow_sql_for_update.php index 3ba2a18bc..1aac88955 100644 --- a/tests/integration/pdo/test_instance_slow_sql_for_update.php +++ b/tests/integration/pdo/test_instance_slow_sql_for_update.php @@ -36,7 +36,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ? for update;", + "select * from information_schema.tables limit ? for update;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -66,7 +66,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1 for update;'); + $result = $conn->query('select * from information_schema.tables limit 1 for update;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_instance_slow_sql_lock.php b/tests/integration/pdo/test_instance_slow_sql_lock.php index 798d4272d..ea3db1bc7 100644 --- a/tests/integration/pdo/test_instance_slow_sql_lock.php +++ b/tests/integration/pdo/test_instance_slow_sql_lock.php @@ -37,7 +37,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ? lock in share mode;", + "select * from information_schema.tables limit ? lock in share mode;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -67,7 +67,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1 lock in share mode;'); + $result = $conn->query('select * from information_schema.tables limit 1 lock in share mode;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_instance_slow_sql_semicolon.php b/tests/integration/pdo/test_instance_slow_sql_semicolon.php index 2c07e0023..c26da78ed 100644 --- a/tests/integration/pdo/test_instance_slow_sql_semicolon.php +++ b/tests/integration/pdo/test_instance_slow_sql_semicolon.php @@ -36,7 +36,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables where engine = ?;", + "select * from information_schema.tables where engine = ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -66,7 +66,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables where engine = \';\';'); + $result = $conn->query('select * from information_schema.tables where engine = \';\';'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_null_options.php b/tests/integration/pdo/test_null_options.php index 16e522a57..ea61e7343 100644 --- a/tests/integration/pdo/test_null_options.php +++ b/tests/integration/pdo/test_null_options.php @@ -32,7 +32,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -85,7 +85,7 @@ function test_slow_sql() { $options = null; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, $options); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_null_options.php81.php b/tests/integration/pdo/test_null_options.php81.php index 528855b81..6f61e3a00 100644 --- a/tests/integration/pdo/test_null_options.php81.php +++ b/tests/integration/pdo/test_null_options.php81.php @@ -32,7 +32,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -85,7 +85,7 @@ function test_slow_sql() { $options = null; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, $options); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_persistent_conn.php b/tests/integration/pdo/test_persistent_conn.php index b44785305..b5453d889 100644 --- a/tests/integration/pdo/test_persistent_conn.php +++ b/tests/integration/pdo/test_persistent_conn.php @@ -32,7 +32,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -86,7 +86,7 @@ function test_slow_sql() $options = array(PDO::ATTR_PERSISTENT => true); $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, $options); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_persistent_conn.php81.php b/tests/integration/pdo/test_persistent_conn.php81.php index ad185d896..2c669bd7f 100644 --- a/tests/integration/pdo/test_persistent_conn.php81.php +++ b/tests/integration/pdo/test_persistent_conn.php81.php @@ -32,7 +32,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -86,7 +86,7 @@ function test_slow_sql() $options = array(PDO::ATTR_PERSISTENT => true); $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, $options); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_prepared_stmt_basic.inc b/tests/integration/pdo/test_prepared_stmt_basic.inc new file mode 100644 index 000000000..4db6fd87b --- /dev/null +++ b/tests/integration/pdo/test_prepared_stmt_basic.inc @@ -0,0 +1,31 @@ +prepare($query); + tap_assert($stmt->execute(), 'execute prepared statement'); +} diff --git a/tests/integration/pdo/test_prepared_stmt_bind_value.inc b/tests/integration/pdo/test_prepared_stmt_bind_value.inc new file mode 100644 index 000000000..6ba2ffd82 --- /dev/null +++ b/tests/integration/pdo/test_prepared_stmt_bind_value.inc @@ -0,0 +1,32 @@ +prepare($query); + $stmt->bindValue(1, "missing"); + tap_assert($stmt->execute(), 'execute prepared statement'); +} diff --git a/tests/integration/pdo/test_prepared_stmt_params.php b/tests/integration/pdo/test_prepared_stmt_params.php index cd097e04f..7bb92e7c3 100644 --- a/tests/integration/pdo/test_prepared_stmt_params.php +++ b/tests/integration/pdo/test_prepared_stmt_params.php @@ -36,7 +36,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables where table_name = ? limit ?;", + "select * from information_schema.tables where table_name = ? limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -88,7 +88,7 @@ function test_prepared_statement() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables where table_name = ? limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables where table_name = ? limit 1;'); $stmt->bindValue(1, "missing"); tap_assert($stmt->execute(), 'execute prepared statement with a param'); } diff --git a/tests/integration/pdo/test_prepared_stmt_params.php81.php b/tests/integration/pdo/test_prepared_stmt_params.php81.php index 001b38dd3..5c1b40c99 100644 --- a/tests/integration/pdo/test_prepared_stmt_params.php81.php +++ b/tests/integration/pdo/test_prepared_stmt_params.php81.php @@ -36,7 +36,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables where table_name = ? limit ?;", + "select * from information_schema.tables where table_name = ? limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -88,7 +88,7 @@ function test_prepared_statement() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables where table_name = ? limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables where table_name = ? limit 1;'); $stmt->bindValue(1, "missing"); tap_assert($stmt->execute(), 'execute prepared statement with a param'); } diff --git a/tests/integration/pdo/test_query_1_arg.inc b/tests/integration/pdo/test_query_1_arg.inc new file mode 100644 index 000000000..104405786 --- /dev/null +++ b/tests/integration/pdo/test_query_1_arg.inc @@ -0,0 +1,51 @@ +exec("CREATE TABLE test (id INT, description VARCHAR(10));"), 'create table'); + + tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); + + $expected = array( + array('id' => 1, 'description' => 'one'), + array('id' => 2, 'description' => 'two'), + array('id' => 3, 'description' => 'three') + ); + + $result = $conn->query('SELECT * FROM test;'); + $actual = $result->fetchAll(PDO::FETCH_ASSOC); + $result->closeCursor(); + // normalize id to int type + array_walk($actual, function (&$row, $key) { + $row['id'] = intval($row['id']); + }); + tap_equal($expected, $actual, 'query (1-arg)'); + + tap_equal($want_drop_table_result, $conn->exec("DROP TABLE test;"), 'drop table'); +} diff --git a/tests/integration/pdo/test_query_fetch_class.inc b/tests/integration/pdo/test_query_fetch_class.inc new file mode 100644 index 000000000..4aef4c76f --- /dev/null +++ b/tests/integration/pdo/test_query_fetch_class.inc @@ -0,0 +1,44 @@ +exec("CREATE TABLE test (id INT, description VARCHAR(10));"), 'create table'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert row'); + + $expected = new Row(); + $expected->id = '1'; + $expected->description = 'one'; + + $actual = $conn->query('SELECT * FROM test;', PDO::FETCH_CLASS, 'Row')->fetch(); + tap_assert($expected == $actual, 'fetch row as object'); + + tap_equal($want_drop_table_result, $conn->exec("DROP TABLE test;"), 'drop table'); +} diff --git a/tests/integration/pdo/test_query_fetch_column.inc b/tests/integration/pdo/test_query_fetch_column.inc new file mode 100644 index 000000000..df1c590e5 --- /dev/null +++ b/tests/integration/pdo/test_query_fetch_column.inc @@ -0,0 +1,40 @@ +exec("CREATE TABLE test (id INT, description VARCHAR(10));"), 'create table'); + + tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert one'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (2, 'two');"), 'insert two'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (3, 'three');"), 'insert three'); + + $result = $conn->query('SELECT * FROM test;', PDO::FETCH_COLUMN, 1); + $actual = $result->fetchAll(PDO::FETCH_ASSOC); + $result->closeCursor(); + tap_equal(3, count($actual), 'fetch column'); + + tap_equal($want_drop_table_result, $conn->exec("DROP TABLE test;"), 'drop table'); +} diff --git a/tests/integration/pdo/test_query_fetch_into.inc b/tests/integration/pdo/test_query_fetch_into.inc new file mode 100644 index 000000000..2cc144881 --- /dev/null +++ b/tests/integration/pdo/test_query_fetch_into.inc @@ -0,0 +1,45 @@ +exec("CREATE TABLE test (id INT, description VARCHAR(10));"), 'create table'); + tap_equal(1, $conn->exec("INSERT INTO test VALUES (1, 'one');"), 'insert row'); + + $expected = new Row(); + $expected->id = '1'; + $expected->description = 'one'; + + $actual = new Row(); + $conn->query('SELECT * FROM test;', PDO::FETCH_INTO, $actual)->fetch(); + tap_assert($expected == $actual, 'fetch row into object'); + + tap_equal($want_drop_table_result, $conn->exec("DROP TABLE test;"), 'drop table'); +} diff --git a/tests/integration/pdo/test_slow_sql_1.php b/tests/integration/pdo/test_slow_sql_1.php index 84e0aa06c..86b4aea7f 100644 --- a/tests/integration/pdo/test_slow_sql_1.php +++ b/tests/integration/pdo/test_slow_sql_1.php @@ -31,7 +31,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -83,7 +83,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_slow_sql_1.php81.php b/tests/integration/pdo/test_slow_sql_1.php81.php index 6d5b4064e..e420b7b97 100644 --- a/tests/integration/pdo/test_slow_sql_1.php81.php +++ b/tests/integration/pdo/test_slow_sql_1.php81.php @@ -31,7 +31,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -83,7 +83,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_slow_sql_2.php b/tests/integration/pdo/test_slow_sql_2.php index f2f928385..2c3bb54d2 100644 --- a/tests/integration/pdo/test_slow_sql_2.php +++ b/tests/integration/pdo/test_slow_sql_2.php @@ -35,7 +35,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -87,7 +87,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables limit 1;'); tap_assert($stmt->execute(), 'execute slow query'); } diff --git a/tests/integration/pdo/test_slow_sql_2.php81.php b/tests/integration/pdo/test_slow_sql_2.php81.php index a80a43510..f52008c2c 100644 --- a/tests/integration/pdo/test_slow_sql_2.php81.php +++ b/tests/integration/pdo/test_slow_sql_2.php81.php @@ -35,7 +35,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ?;", + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -87,7 +87,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $stmt = $conn->prepare('select * from tables limit 1;'); + $stmt = $conn->prepare('select * from information_schema.tables limit 1;'); tap_assert($stmt->execute(), 'execute slow query'); } diff --git a/tests/integration/pdo/test_slow_sql_for_update.php b/tests/integration/pdo/test_slow_sql_for_update.php index 2a074b689..63e75d373 100644 --- a/tests/integration/pdo/test_slow_sql_for_update.php +++ b/tests/integration/pdo/test_slow_sql_for_update.php @@ -28,7 +28,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ? for update;", + "select * from information_schema.tables limit ? for update;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -51,7 +51,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1 for update;'); + $result = $conn->query('select * from information_schema.tables limit 1 for update;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_slow_sql_lock.php b/tests/integration/pdo/test_slow_sql_lock.php index c87464ad3..7f1d07722 100644 --- a/tests/integration/pdo/test_slow_sql_lock.php +++ b/tests/integration/pdo/test_slow_sql_lock.php @@ -28,7 +28,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables limit ? lock in share mode;", + "select * from information_schema.tables limit ? lock in share mode;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -51,7 +51,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables limit 1 lock in share mode;'); + $result = $conn->query('select * from information_schema.tables limit 1 lock in share mode;'); } test_slow_sql(); diff --git a/tests/integration/pdo/test_slow_sql_semicolon.php b/tests/integration/pdo/test_slow_sql_semicolon.php index 87901b7e5..4f88e76d5 100644 --- a/tests/integration/pdo/test_slow_sql_semicolon.php +++ b/tests/integration/pdo/test_slow_sql_semicolon.php @@ -28,7 +28,7 @@ "OtherTransaction/php__FILE__", "", "?? SQL id", - "select * from tables where engine = ?;", + "select * from information_schema.tables where engine = ?;", "Datastore/statement/MySQL/tables/select", 1, "?? total time", @@ -51,7 +51,7 @@ function test_slow_sql() { global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD); - $result = $conn->query('select * from tables where engine = \';\';'); + $result = $conn->query('select * from information_schema.tables where engine = \';\';'); } test_slow_sql(); diff --git a/tests/lasp/suite-least-secure/test_slow_sql_on.php b/tests/lasp/suite-least-secure/test_slow_sql_on.php index e4b693b0b..003595b14 100644 --- a/tests/lasp/suite-least-secure/test_slow_sql_on.php +++ b/tests/lasp/suite-least-secure/test_slow_sql_on.php @@ -31,8 +31,8 @@ [ "OtherTransaction/php__FILE__", "\u003cunknown\u003e", - 2691358128, - "select * from tables limit ?;", + 2279837883, + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", "??", "??", @@ -85,7 +85,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-least-secure/test_slow_sql_on.php81.php b/tests/lasp/suite-least-secure/test_slow_sql_on.php81.php index b4e678a8b..a9696beb7 100644 --- a/tests/lasp/suite-least-secure/test_slow_sql_on.php81.php +++ b/tests/lasp/suite-least-secure/test_slow_sql_on.php81.php @@ -31,8 +31,8 @@ [ "OtherTransaction/php__FILE__", "\u003cunknown\u003e", - 2691358128, - "select * from tables limit ?;", + 2279837883, + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", "??", "??", @@ -85,7 +85,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-most-secure/test_slow_sql_off.php b/tests/lasp/suite-most-secure/test_slow_sql_off.php index e5e252eea..e464fd0d0 100644 --- a/tests/lasp/suite-most-secure/test_slow_sql_off.php +++ b/tests/lasp/suite-most-secure/test_slow_sql_off.php @@ -35,7 +35,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-random-2/test_slow_sql_on.php b/tests/lasp/suite-random-2/test_slow_sql_on.php index b68fb481f..c1e86a5fa 100644 --- a/tests/lasp/suite-random-2/test_slow_sql_on.php +++ b/tests/lasp/suite-random-2/test_slow_sql_on.php @@ -30,8 +30,8 @@ [ "OtherTransaction/php__FILE__", "\u003cunknown\u003e", - 2691358128, - "select * from tables limit ?;", + 2279837883, + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", "??", "??", @@ -84,7 +84,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-random-2/test_slow_sql_on.php81.php b/tests/lasp/suite-random-2/test_slow_sql_on.php81.php index d229271ef..c25195200 100644 --- a/tests/lasp/suite-random-2/test_slow_sql_on.php81.php +++ b/tests/lasp/suite-random-2/test_slow_sql_on.php81.php @@ -30,8 +30,8 @@ [ "OtherTransaction/php__FILE__", "\u003cunknown\u003e", - 2691358128, - "select * from tables limit ?;", + 2279837883, + "select * from information_schema.tables limit ?;", "Datastore/statement/MySQL/tables/select", "??", "??", @@ -84,7 +84,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-random-3/test_slow_sql_off.php b/tests/lasp/suite-random-3/test_slow_sql_off.php index 18c3c7f84..087f130bb 100644 --- a/tests/lasp/suite-random-3/test_slow_sql_off.php +++ b/tests/lasp/suite-random-3/test_slow_sql_off.php @@ -34,7 +34,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/lasp/suite-random-3/test_slow_sql_on.php b/tests/lasp/suite-random-3/test_slow_sql_on.php index d55b78edf..6ec54ea93 100644 --- a/tests/lasp/suite-random-3/test_slow_sql_on.php +++ b/tests/lasp/suite-random-3/test_slow_sql_on.php @@ -34,7 +34,7 @@ function test_slow_sql() global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, array()); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } test_slow_sql(); diff --git a/tests/regression/test_php_1179_pdo_options_crash.php b/tests/regression/test_php_1179_pdo_options_crash.php index e35ca7f0a..9b6419337 100644 --- a/tests/regression/test_php_1179_pdo_options_crash.php +++ b/tests/regression/test_php_1179_pdo_options_crash.php @@ -59,7 +59,7 @@ function test_slow_sql(array $options) global $PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD; $conn = new PDO($PDO_MYSQL_DSN, $MYSQL_USER, $MYSQL_PASSWD, $options); - $result = $conn->query('select * from tables limit 1;'); + $result = $conn->query('select * from information_schema.tables limit 1;'); } $shared_options = array(PDO::ATTR_PERSISTENT => true);