Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: ['7.2', '7.3', '7.4', '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
15 changes: 10 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,37 @@ cache:
clone_folder: c:\projects\dibi

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

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

install:
# Install PHP 7.2
# Install PHP 7.4
- 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
- IF %PHP%==1 curl https://windows.php.net/downloads/releases/archives/php-7.4.19-Win32-vc15-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-7.4.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-7.4\x64\php_sqlsrv_74_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 Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"tracy/tracy": "~2.2",
"nette/tester": "~2.0",
"nette/di": "^3.0",
"phpstan/phpstan": "^0.12"
"phpstan/phpstan": "^0.12",
"nette/code-checker": "^3.2"
},
"replace": {
"dg/dibi": "*"
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/DummyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
{
use Dibi\Strict;
use NoParameterizedQueries;

public function disconnect(): void
{
Expand Down Expand Up @@ -129,7 +130,6 @@ public function escapeLike(string $value, int $pos): string
return ($pos & 1 ? "'%" : "'") . $value . ($pos & 2 ? "%'" : "'");
}


/**
* Injects LIMIT/OFFSET to the SQL query.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Dibi/Drivers/FirebirdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class FirebirdDriver implements Dibi\Driver
{
use Dibi\Strict;
use NoParameterizedQueries;

public const ERROR_EXCEPTION_THROWN = -836;

Expand Down
1 change: 1 addition & 0 deletions src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class MySqliDriver implements Dibi\Driver
{
use Dibi\Strict;
use NoParameterizedQueries;

public const ERROR_ACCESS_DENIED = 1045;

Expand Down
71 changes: 71 additions & 0 deletions src/Dibi/Drivers/NoParameterizedQueries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
*/

declare(strict_types=1);

namespace Dibi\Drivers;

use Dibi\NotSupportedException;
use Dibi\QueryParameter;

/**
* Better OOP experience.
*/
trait NoParameterizedQueries
{
public function addParameter(QueryParameter $param): void {
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindText(?string $value, ?string $length = null, ?string $encoding = null): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindAsciiText(?string $value, ?string $length = null, ?string $encoding = null): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindIdentifier(?string $value): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindInt(?int $value): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindNumeric(?float $value, string $precision, string $scale): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindDate(?\DateTimeInterface $value): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindDateTime(?\DateTimeInterface $value): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}


public function bindDateInterval(?\DateInterval $value): QueryParameter
{
throw new NotSupportedException('Parameterized queries unsupported');
}
}
1 change: 1 addition & 0 deletions src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class OdbcDriver implements Dibi\Driver
{
use Dibi\Strict;
use NoParameterizedQueries;

/** @var resource */
private $connection;
Expand Down
1 change: 1 addition & 0 deletions src/Dibi/Drivers/OracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class OracleDriver implements Dibi\Driver
{
use Dibi\Strict;
use NoParameterizedQueries;

/** @var resource */
private $connection;
Expand Down
Loading