Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterized query support v next #396

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d24fc4d
added github workflows
dg Apr 23, 2021
b74ef09
opened 5.0-dev
dg Mar 1, 2021
2ef62cd
requires PHP 8.0
dg Mar 1, 2021
3cb9c7a
composer: updated dependencies
dg Mar 1, 2021
e1fd958
coding style
dg Mar 1, 2021
03b1f1b
removed support for PHP 7
dg Mar 10, 2021
9fb73cb
added property typehints
dg Mar 1, 2021
15a9c98
added PHP 8 typehints
dg Mar 1, 2021
4884583
sqlsrv_configure after sqlsrv_errors
May 26, 2021
c3b365e
sqlsrv_configure after sqlsrv_errors
May 26, 2021
35a8ee7
Sqlsrv driver parameterized query support
gabema Jun 22, 2021
32a675f
Changing %tsql to %pq for parameterized query substitution
gabema Jun 24, 2021
2ad3592
Fix PDO usage and be sure to reset query params between queries
gabema Jun 24, 2021
a138466
Code formatting / cleanup
gabema Jun 24, 2021
63a7076
Fixes code checker errors
gabema Jun 25, 2021
06dc273
Temporarily removing query parameter support for pdo driver
gabema Jun 25, 2021
493eec8
Updating appveyor to PHP 7.4 to support MS 5.9 libraries
gabema Jun 25, 2021
62d8706
Updating ODBC Driver install for appveyor and referencing "function-l…
gabema Jun 28, 2021
57af572
updating curl command
gabema Jun 29, 2021
6289031
Merging Parameterized query driver support into master
gabema Jun 29, 2021
41fdfbd
Re-adding support for PdoDriver query parameter support. Updating App…
gabema Jun 29, 2021
77adc8c
Attempt to fix broken test related to SQL server drivers 'function li…
gabema Jun 29, 2021
8463aab
Merge branch 'ParameterizedQuerySupport' into ParameterizedQuerySuppo…
gabema Jun 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Coding Style

on: [push, pull_request]

jobs:
nette_cc:
name: Nette Code Checker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
- run: php temp/code-checker/code-checker --strict-types --no-progress --ignore "tests/*/fixtures"


nette_cs:
name: Nette Coding Standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress --ignore-platform-reqs
- run: php temp/coding-standard/ecs check
21 changes: 21 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Static Analysis (only informative)

on:
push:
branches:
- master

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
- run: composer phpstan -- --no-progress
continue-on-error: true # is only informative
121 changes: 121 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Tests

on: [push, pull_request]

env:
php-extensions: mbstring, intl, mysqli, pgsql, sqlsrv-5.9.0preview1, pdo_sqlsrv-5.9.0preview1
php-tools: "composer:v2, pecl"

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.0']

fail-fast: false

name: PHP ${{ matrix.php }} tests

services:
mysql57:
image: mysql:5.7
env:
MYSQL_DATABASE: dibi_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10

mysql80:
image: mysql:8.0
ports:
- 3307:3306
options: >-
--health-cmd="mysqladmin ping -ppass"
--health-interval=10s
--health-timeout=5s
--health-retries=5
-e MYSQL_ROOT_PASSWORD=root
-e MYSQL_DATABASE=dibi_test
--entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"

postgres96:
image: postgres:9.6
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dibi_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

postgres13:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dibi_test
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

mssql:
image: mcr.microsoft.com/mssql/server:latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: YourStrong!Passw0rd
MSSQL_PID: Developer
ports:
- 1433:1433
options: >-
--name=mssql
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.php-extensions }}
tools: ${{ env.php-tools }}
coverage: none

- name: Create databases.ini
run: cp ./tests/databases.github.ini ./tests/databases.ini

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE dibi_test'

- run: composer install --no-progress --prefer-dist
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
- if: failure()
uses: actions/upload-artifact@v2
with:
name: output
path: tests/**/output


- name: Save Code Coverage
if: ${{ matrix.php == '8.0' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
php php-coveralls.phar --verbose --config tests/.coveralls.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
/composer.lock
/.vscode
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: php
php:
- 7.2
- 7.3
- 7.4
- 8.0snapshot
- 8.0
- 8.0

services:
- mysql
Expand Down Expand Up @@ -39,21 +37,21 @@ jobs:


- name: Nette Coding Standard
php: 7.4
php: 8.0
install:
- travis_retry composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress
script:
- php temp/coding-standard/ecs check src tests


- stage: Static Analysis (informative)
php: 7.4
php: 8.0
script:
- composer run-script phpstan


- stage: Code Coverage
php: 7.4
php: 8.0
script:
- vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src
after_script:
Expand Down
27 changes: 16 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
build: off
cache:
- c:\php7 -> appveyor.yml
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files -> appveyor.yml'

clone_folder: c:\projects\dibi

services:
- mssql2012sp1
# - mssql2012sp1
# - mssql2014
- mssql2016
- mysql

init:
- SET PATH=c:\php7;%PATH%
- SET PATH=c:\php;%PATH%
- SET ANSICON=121x90 (121x90)

install:
# Install PHP 7.2
- IF EXIST c:\php7 (SET PHP=0) ELSE (SET PHP=1)
- IF %PHP%==1 mkdir c:\php7
- IF %PHP%==1 cd c:\php7
- IF %PHP%==1 curl https://windows.php.net/downloads/releases/archives/php-7.2.18-Win32-VC15-x64.zip --output php.zip
# Install PHP 8.0
- IF EXIST c:\php (SET PHP=0) ELSE (SET PHP=1)
- IF %PHP%==1 mkdir c:\php
- IF %PHP%==1 cd c:\php
- IF %PHP%==1 curl https://windows.php.net/downloads/releases/archives/php-8.0.1-Win32-vs16-x64.zip --output php.zip
- IF %PHP%==1 7z x php.zip >nul
- IF %PHP%==1 echo extension_dir=ext >> php.ini
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 curl https://github.com/microsoft/msphpsql/releases/download/v5.8.0/Windows-7.2.zip -L --output sqlsrv.zip
- IF %PHP%==1 curl https://github.com/microsoft/msphpsql/releases/download/v5.9.0/Windows-8.0.zip -L --output sqlsrv.zip
- IF %PHP%==1 7z x sqlsrv.zip >nul
- IF %PHP%==1 copy Windows-7.2\x64\php_sqlsrv_72_ts.dll ext\php_sqlsrv_ts.dll
- IF %PHP%==1 copy Windows-8.0\x64\php_sqlsrv_80_ts.dll ext\php_sqlsrv_ts.dll
- IF %PHP%==1 del /Q *.zip

# Install Microsoft Access Database Engine x64
- IF %PHP%==1 curl https://download.microsoft.com/download/2/4/3/24375141-E08D-4803-AB0E-10F2E3A07AAA/AccessDatabaseEngine_X64.exe --output AccessDatabaseEngine_X64.exe
- cmd /c start /wait AccessDatabaseEngine_X64.exe /passive

# Install ODBC Driver for SQL Server x64 Version 17.7.2
- IF %PHP%==1 curl --silent --location --output msodbcsql.msi https://go.microsoft.com/fwlink/?linkid=2156851
- cmd /c start /wait msiexec /qn /passive /i msodbcsql.msi

# Install Nette Tester
- cd c:\projects\dibi
- appveyor DownloadFile https://getcomposer.org/composer.phar
Expand All @@ -41,7 +46,7 @@ install:
- copy tests\databases.appveyor.ini tests\databases.ini

test_script:
- vendor\bin\tester tests -s -p c:\php7\php -c tests\php-win.ini
- vendor\bin\tester tests -s -p c:\php\php -c tests\php-win.ini

on_failure:
# Print *.actual content
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
}
],
"require": {
"php": ">=7.2"
"php": ">=8.0 <8.1"
},
"require-dev": {
"tracy/tracy": "~2.2",
"nette/tester": "~2.0",
"tracy/tracy": "^2.8",
"nette/tester": "^2.4",
"nette/di": "^3.0",
"phpstan/phpstan": "^0.12"
"phpstan/phpstan": "^0.12",
"nette/code-checker": "^3.2"
},
"replace": {
"dg/dibi": "*"
Expand All @@ -31,7 +32,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
"dev-master": "5.0-dev"
}
}
}
12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Install Dibi via Composer:
composer require dibi/dibi
```

The Dibi 4.2 requires PHP version 7.2 and supports PHP up to 8.0.
The Dibi 4.2 requires PHP version 8.0.


Usage
Expand Down Expand Up @@ -176,6 +176,7 @@ In addition to the `?` wildcard char, we can also use modifiers:
| %ex | SQL expression or array of expressions
| %lmt | special - adds LIMIT to the query
| %ofs | special - adds OFFSET to the query
| %pq | special - sends the parameterized query down to the underlying DB driver for binding

Example:

Expand All @@ -202,6 +203,15 @@ $result = $database->query('SELECT * FROM %n WHERE %n = ?', $table, $column, $va
// SELECT * FROM `blog`.`users` WHERE `name` = 'Jim'
```

The modifier `%pq` inserts a `?` into the query sent to the underlying database driver and allows the caller to bind the parameterized query values to the positional modifiers.

Example:

```php
$result = $database->query('SELECT * FROM users WHERE name = %pq', $database->getDriver()->bindText($name));
// SELECT * FROM `users` WHERE `name` = ?
```

Three special modifiers are available for LIKE:

| modifier | description
Expand Down
5 changes: 2 additions & 3 deletions src/Dibi/Bridges/Nette/DibiExtension22.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*/
class DibiExtension22 extends Nette\DI\CompilerExtension
{
/** @var bool|null */
private $debugMode;
private ?bool $debugMode;


public function __construct(bool $debugMode = null)
Expand Down Expand Up @@ -57,7 +56,7 @@ public function loadConfiguration()
if (class_exists(Tracy\Debugger::class)) {
$connection->addSetup(
[new Nette\DI\Statement('Tracy\Debugger::getBlueScreen'), 'addPanel'],
[[Dibi\Bridges\Tracy\Panel::class, 'renderException']]
[[Dibi\Bridges\Tracy\Panel::class, 'renderException']],
);
}
if ($useProfiler) {
Expand Down
15 changes: 6 additions & 9 deletions src/Dibi/Bridges/Tracy/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ class Panel implements Tracy\IBarPanel
{
use Dibi\Strict;

/** @var int maximum SQL length */
public static $maxLength = 1000;
/** maximum SQL length */
public static int $maxLength = 1000;

/** @var bool|string explain queries? */
public $explain;
public bool|string $explain;

/** @var int */
public $filter;
public int $filter;

/** @var array */
private $events = [];
private array $events = [];


public function __construct($explain = true, int $filter = null)
public function __construct(bool $explain = true, int $filter = null)
{
$this->filter = $filter ?: Event::QUERY;
$this->explain = $explain;
Expand Down
Loading