From a1ba6ed304c2beae36026a975c0c12ba712226df Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 11 Jan 2021 12:30:07 -0500 Subject: [PATCH 001/148] update CI yml --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7bb41573..869e733d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,4 +31,4 @@ after_success: # Commands you want to run that will verify your build. script: - vendor/bin/phpunit --coverage-clover=coverage.xml - - vendor/bin/phpstan analyse lib tests --level=1 +# - vendor/bin/phpstan analyse lib tests --level=1 diff --git a/appveyor.yml b/appveyor.yml index 67245644..fae08721 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -81,7 +81,7 @@ install: - IF %PHP%==1 echo xdebug.profiler_enable=off >> php.ini - cd c:\projects\php-project-workspace - composer self-update - - composer require phpstan/phpstan "0.11.3" + ## - composer require phpstan/phpstan "0.11.3" build_script: # postgres From e71fcd4012fd08128282023c3e0442ba47b24dea Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 11 Jan 2021 14:19:53 -0500 Subject: [PATCH 002/148] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 869e733d..6850db25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 7.1 - 7.2 - 7.4 + - 8.0 env: - MYSQL_HOST=127.0.0.1 MYSQL_USER=root From 33e11036ccc81f6bca81fc1d3a71afb420305695 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 16:21:52 -0500 Subject: [PATCH 003/148] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6850db25..b5a205e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ services: # Commands to be run before your environment runs. before_script: - composer self-update - - composer require phpstan/phpstan "0.11.3" +# - composer require phpstan/phpstan "0.11.3" - mysql -e 'CREATE DATABASE IF NOT EXISTS ez_test;' - mysql -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - psql -c 'CREATE DATABASE ez_test;' -U postgres From bdb4b6ec8a0e98f3e708d7b9e40117f4e1fb8542 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 22:21:49 -0500 Subject: [PATCH 004/148] Test initial setup for using Github Actions CI --- .github/workflows/ezsql-linux.yml | 47 ++++++++++++ .travis.yml | 35 --------- appveyor.yml | 114 ------------------------------ 3 files changed, 47 insertions(+), 149 deletions(-) create mode 100644 .github/workflows/ezsql-linux.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml new file mode 100644 index 00000000..417a5861 --- /dev/null +++ b/.github/workflows/ezsql-linux.yml @@ -0,0 +1,47 @@ +# GitHub Action for PHP with extensions +name: ezsql-linux + +on: [push, pull_request] + +jobs: + linux: + name: Linux (PHP ${{ matrix.php-versions }} CI) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest] + php: ['7.1', '7.2', '7.4', '8.0'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + coverage: xdebug + - name: Star MySQL + run: sudo systemctl start mysql.service + - name: Setup MySQL Database + run: | + mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Setup PostgreSql Database + run: | + psql -c 'CREATE DATABASE ez_test;' -U postgres + psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres + - name: Setup SQLServer Database + run: | + # MSSQLLocalDB is the default SQL LocalDB instance + SqlLocalDB start MSSQLLocalDB + SqlLocalDB info MSSQLLocalDB + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + - name: Install dependencies + run: composer install --no-progress + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-clover + - name: Submit code coverage + run: bash <(curl -s https://codecov.io/bash) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b5a205e8..00000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: php - -# Versions of PHP you want your project run with. -php: - - 7.1 - - 7.2 - - 7.4 - - 8.0 - -env: - - MYSQL_HOST=127.0.0.1 MYSQL_USER=root - -services: - - mysql - - postgresql - -# Commands to be run before your environment runs. -before_script: - - composer self-update -# - composer require phpstan/phpstan "0.11.3" - - mysql -e 'CREATE DATABASE IF NOT EXISTS ez_test;' - - mysql -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - - psql -c 'CREATE DATABASE ez_test;' -U postgres - - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres -# - mysql -e 'GRANT ALL PRIVILEGES ON ez_test.* TO ez_test@localhost;' -# - mysql -e "SET PASSWORD FOR 'ez_test'@'localhost' = PASSWORD('ezTest')" - -after_success: - - bash <(curl -s https://codecov.io/bash) - - travis_retry php vendor/bin/php-coveralls - -# Commands you want to run that will verify your build. -script: - - vendor/bin/phpunit --coverage-clover=coverage.xml -# - vendor/bin/phpstan analyse lib tests --level=1 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 2804ddcf..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,114 +0,0 @@ -build: false -platform: - - x64 -clone_folder: c:\projects\php-project-workspace - -## Build matrix for lowest and highest possible targets -environment: - matrix: - - php_ver_target: 7.3.11 - MYSQL_DATABASE: ez_test - MYSQL_HOST: localhost - MYSQL_USER: root - MYSQL_PASSWORD: Password12! - MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 5.7 - -services: - - mssql2014 - - mysql - - postgresql - -## Set up environment variables -init: - - SET COMPOSER_NO_INTERACTION=1 - - SET PHP=1 # This var is connected to PHP install cache - - SET ANSICON=121x90 (121x90) - -## Install PHP and composer, and run the appropriate composer command Get the MSSQL DLL's and XDEBUG -install: - # Enable Windows Update service, needed to install vcredist2015 (dependency of php) - - IF EXIST c:\tools\php73 (SET PHP=0) - - ps: Set-Service wuauserv -StartupType Manual - - choco config set cacheLocation %LOCALAPPDATA%\Temp\Chocolatey - - choco install -y php --version %php_ver_target% - - choco install -y sqlite - - choco install -y composer - - refreshenv - - composer install --no-interaction --no-progress --prefer-dist - - cd C:\tools\php73 - # Get the MSSQL DLL's - - ps: >- - If ($env:PHP -eq "1") { - $DLLVersion = "5.6.1" - cd C:\tools\php73\ext - $source = "http://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - $destination = "C:\tools\php73\ext\php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - Invoke-WebRequest $source -OutFile $destination - 7z x -y php_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip > $null - $source = "http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - $destination = "C:\tools\php73\ext\php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip" - Invoke-WebRequest $source -OutFile $destination - 7z x -y php_pdo_sqlsrv-$($DLLVersion)-7.3-nts-vc15-x64.zip > $null - Remove-Item C:\tools\php73\ext* -include .zip - Invoke-WebRequest "https://xdebug.org/files/php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll" -OutFile "C:\tools\php73\ext\php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll" - cd C:\tools\php73 - } - - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - - IF %PHP%==1 echo extension_dir=ext >> php.ini - - IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini - - ps: >- - If ($env:php_ver_target -eq "5.6") { - Add-Content php.ini "`nextension=php_sqlsrv_nts.dll" - Add-Content php.ini "`nextension=php_pdo_sqlsrv_nts.dll" - Add-Content php.ini "`n" - } Else { - Add-Content php.ini "`nextension=php_sqlsrv.dll" - Add-Content php.ini "`nextension=php_pdo_sqlsrv.dll" - Add-Content php.ini "`n" - } - - IF %PHP%==1 echo extension=php_pgsql.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_pgsql.dll >> php.ini - - IF %PHP%==1 echo extension=php_sqlite3.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_sqlite.dll >> php.ini - - IF %PHP%==1 echo extension=php_mysqli.dll >> php.ini - - IF %PHP%==1 echo extension=php_pdo_mysql.dll >> php.ini - - IF %PHP%==1 echo [xdebug] >> php.ini - - IF %PHP%==1 echo zend_extension=php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll >> php.ini - - IF %PHP%==1 echo zend.assertions=1 >> php.ini - - IF %PHP%==1 echo assert.exception=On >> php.ini - - IF %PHP%==1 echo xdebug.remote_enable=1 >> php.ini - - IF %PHP%==1 echo xdebug.remote_autostart=1 >> php.ini - - IF %PHP%==1 echo xdebug.profiler_enable=off >> php.ini - - cd c:\projects\php-project-workspace - - composer self-update -# - composer require phpstan/phpstan "0.11.3" - -build_script: - # postgres - - SET PGUSER=postgres - - SET PGPASSWORD=Password12! - - PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH% - - createdb ez_test - - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - # sqlserver - - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" - - sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - -before_test: - - SET PATH=%MYSQL_PATH%\bin;%PATH% - - mysqladmin --host=%MYSQL_HOST% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% create %MYSQL_DATABASE% - # mysql - - mysql -u root -p"Password12!" -e "CREATE DATABASE IF NOT EXISTS ez_test;" - - mysql -u root -p"Password12!" -e "GRANT ALL PRIVILEGES ON ez_test.* TO ez_test@localhost IDENTIFIED BY 'ezTest'"; - - mysql -u root -p"Password12!" -e "FLUSH PRIVILEGES;" - -on_success: - - ps: | - $env:PATH = 'C:\msys64\usr\bin;' + $env:PATH - Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh - bash codecov.sh -f "coverage.xml" - -## Run the actual test -test_script: - - cd c:\projects\php-project-workspace - - vendor\bin\phpunit --coverage-clover=coverage.xml From 376eb4d1bcfeafbc5e031bc69b43f5e6f9ac686d Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 22:25:53 -0500 Subject: [PATCH 005/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 417a5861..82089637 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php: ['7.1', '7.2', '7.4', '8.0'] + php-versions: ['7.1', '7.2', '7.4', '8.0'] steps: - name: Checkout From 1cc7649c407de95561c302101e6d818e1ff3a7e3 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 22:50:32 -0500 Subject: [PATCH 006/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 82089637..c02df43c 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -22,8 +22,10 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug - - name: Star MySQL + - name: Start MySQL run: sudo systemctl start mysql.service + - name: Start PostgreSql + run: sudo systemctl start psql.service - name: Setup MySQL Database run: | mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" From 11b23a7d5aa4ca45d788d318a4384a6fc71b2e40 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 22:55:11 -0500 Subject: [PATCH 007/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index c02df43c..2838c17c 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -25,7 +25,7 @@ jobs: - name: Start MySQL run: sudo systemctl start mysql.service - name: Start PostgreSql - run: sudo systemctl start psql.service + run: sudo systemctl start postgresql.service - name: Setup MySQL Database run: | mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" From 21b1033e2f9f2a8ce7aa4ef4024f88fc3dea44f0 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 2 Feb 2021 23:13:20 -0500 Subject: [PATCH 008/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 2838c17c..ca0a0518 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -32,8 +32,8 @@ jobs: mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - psql -c 'CREATE DATABASE ez_test;' -U postgres - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres + psql -c 'CREATE DATABASE ez_test;' -U postgres -P root + psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres -P root - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 3e335fe8a7c9b7986e9ab59e155ec3dd7527603a Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 12:37:06 -0500 Subject: [PATCH 009/148] update postgresql setup action --- .github/workflows/ezsql-linux.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index ca0a0518..807d94dc 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -12,6 +12,23 @@ jobs: matrix: operating-system: [ubuntu-latest] php-versions: ['7.1', '7.2', '7.4', '8.0'] + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 steps: - name: Checkout @@ -24,16 +41,19 @@ jobs: coverage: xdebug - name: Start MySQL run: sudo systemctl start mysql.service - - name: Start PostgreSql - run: sudo systemctl start postgresql.service - name: Setup MySQL Database run: | mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - psql -c 'CREATE DATABASE ez_test;' -U postgres -P root - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres -P root + psql -c 'CREATE DATABASE ez_test;' -U postgres + psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres + env: + # The hostname used to communicate with the PostgreSQL service container + POSTGRES_HOST: localhost + # The default PostgreSQL port + POSTGRES_PORT: 5432 - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 6bfe46571b0892735afb9d4c435444c6f5cba5be Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 13:34:43 -0500 Subject: [PATCH 010/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 807d94dc..29b43513 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -20,6 +20,7 @@ jobs: # Provide the password for postgres env: POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready @@ -45,10 +46,12 @@ jobs: run: | mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Start PostgreSql + run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - psql -c 'CREATE DATABASE ez_test;' -U postgres - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" -U postgres + psql -h postgres -U postgres -c 'CREATE DATABASE ez_test;' + psql -h postgres -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" env: # The hostname used to communicate with the PostgreSQL service container POSTGRES_HOST: localhost From 747d693a33a25b2ea5d8e3a71720208b9d72143f Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 13:55:07 -0500 Subject: [PATCH 011/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 29b43513..d9b1458e 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -50,8 +50,8 @@ jobs: run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - psql -h postgres -U postgres -c 'CREATE DATABASE ez_test;' - psql -h postgres -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' + psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" env: # The hostname used to communicate with the PostgreSQL service container POSTGRES_HOST: localhost From 6d7bea0c4363b4f83f3eb2bc5688a9c9958f873f Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 14:19:36 -0500 Subject: [PATCH 012/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index d9b1458e..c391b385 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -12,24 +12,6 @@ jobs: matrix: operating-system: [ubuntu-latest] php-versions: ['7.1', '7.2', '7.4', '8.0'] - services: - # Label used to access the service container - postgres: - # Docker Hub image - image: postgres - # Provide the password for postgres - env: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - # Maps tcp port 5432 on service container to the host - - 5432:5432 steps: - name: Checkout @@ -50,13 +32,15 @@ jobs: run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' - psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + psql -h localhost -U postgres -w -c 'CREATE DATABASE ez_test;' + psql -h localhost -U postgres -w -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" env: # The hostname used to communicate with the PostgreSQL service container POSTGRES_HOST: localhost # The default PostgreSQL port POSTGRES_PORT: 5432 + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 5e7f7b104c899ce6ff3147ac855b317cb3b446b0 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 14:46:42 -0500 Subject: [PATCH 013/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index c391b385..d133ca47 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -32,14 +32,14 @@ jobs: run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - psql -h localhost -U postgres -w -c 'CREATE DATABASE ez_test;' - psql -h localhost -U postgres -w -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + export PGPASSWORD='root'; psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' + export PGPASSWORD='root'; psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" env: # The hostname used to communicate with the PostgreSQL service container POSTGRES_HOST: localhost # The default PostgreSQL port POSTGRES_PORT: 5432 - POSTGRES_PASSWORD: postgres + POSTGRES_PASSWORD: root POSTGRES_USER: postgres - name: Setup SQLServer Database run: | From aeab7e08b657360f9981aa21787d0d3654daf742 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 15:00:14 -0500 Subject: [PATCH 014/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index d133ca47..fe333c6e 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -32,15 +32,8 @@ jobs: run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - export PGPASSWORD='root'; psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' - export PGPASSWORD='root'; psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - env: - # The hostname used to communicate with the PostgreSQL service container - POSTGRES_HOST: localhost - # The default PostgreSQL port - POSTGRES_PORT: 5432 - POSTGRES_PASSWORD: root - POSTGRES_USER: postgres + export PGPASSWORD=root; psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' + export PGPASSWORD=root; psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 536a5babe2f94bd91e04893c11612f5d506f5859 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 15:33:41 -0500 Subject: [PATCH 015/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index fe333c6e..e74cf3df 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -10,8 +10,16 @@ jobs: strategy: fail-fast: false matrix: + db: [sqlite, postgres, mysql] operating-system: [ubuntu-latest] php-versions: ['7.1', '7.2', '7.4', '8.0'] + include: + - db: postgres + db_user: runner + db_password: '' + - db: mysql + db_user: root + db_password: root steps: - name: Checkout @@ -32,8 +40,13 @@ jobs: run: sudo systemctl start postgresql.service - name: Setup PostgreSql Database run: | - export PGPASSWORD=root; psql -h localhost -U postgres -c 'CREATE DATABASE ez_test;' - export PGPASSWORD=root; psql -h localhost -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + export PGPASSWORD=; psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' + export PGPASSWORD=; psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + env: + # The hostname used to communicate with the PostgreSQL service container + POSTGRES_HOST: localhost + # The default PostgreSQL port + POSTGRES_PORT: 5432 - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 7efcb95f56374f352fcc346c63e586c5675c9be1 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 15:55:24 -0500 Subject: [PATCH 016/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index e74cf3df..887f1571 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -10,16 +10,8 @@ jobs: strategy: fail-fast: false matrix: - db: [sqlite, postgres, mysql] operating-system: [ubuntu-latest] php-versions: ['7.1', '7.2', '7.4', '8.0'] - include: - - db: postgres - db_user: runner - db_password: '' - - db: mysql - db_user: root - db_password: root steps: - name: Checkout @@ -37,16 +29,18 @@ jobs: mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Start PostgreSql - run: sudo systemctl start postgresql.service - - name: Setup PostgreSql Database run: | - export PGPASSWORD=; psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' - export PGPASSWORD=; psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + sudo systemctl start postgresql.service + sudo -u postgres createuser -s runner + - name: Setup PostgreSql Database env: # The hostname used to communicate with the PostgreSQL service container POSTGRES_HOST: localhost # The default PostgreSQL port POSTGRES_PORT: 5432 + run: | + psql -h localhost -U runner -w -c 'CREATE DATABASE ez_test;' + psql -h localhost -U runner -w -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 1b49986eddac72ed92180462b967745d0d5732a2 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 16:11:11 -0500 Subject: [PATCH 017/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 887f1571..f7c9e58c 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -39,8 +39,9 @@ jobs: # The default PostgreSQL port POSTGRES_PORT: 5432 run: | - psql -h localhost -U runner -w -c 'CREATE DATABASE ez_test;' - psql -h localhost -U runner -w -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + export PGPASSWORD="" + psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' + psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 4db93b2b3d09c93f2fc536023bc838c1f4bf273e Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 16:30:34 -0500 Subject: [PATCH 018/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index f7c9e58c..552314a5 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -30,8 +30,9 @@ jobs: mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Start PostgreSql run: | + export PGPASSWORD=root sudo systemctl start postgresql.service - sudo -u postgres createuser -s runner + sudo -u postgres createuser -P -s -e runner - name: Setup PostgreSql Database env: # The hostname used to communicate with the PostgreSQL service container @@ -39,7 +40,7 @@ jobs: # The default PostgreSQL port POSTGRES_PORT: 5432 run: | - export PGPASSWORD="" + export PGPASSWORD=root psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - name: Setup SQLServer Database From d7dae5eb6149802bab639b417638abd282c54023 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 17:16:08 -0500 Subject: [PATCH 019/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 552314a5..33d816da 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -30,7 +30,6 @@ jobs: mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Start PostgreSql run: | - export PGPASSWORD=root sudo systemctl start postgresql.service sudo -u postgres createuser -P -s -e runner - name: Setup PostgreSql Database @@ -40,7 +39,7 @@ jobs: # The default PostgreSQL port POSTGRES_PORT: 5432 run: | - export PGPASSWORD=root + export PGPASSWORD= psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" - name: Setup SQLServer Database From 9a31aa0d066ee23bd52f41df3fcfd5652a26c6e1 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 19:06:47 -0500 Subject: [PATCH 020/148] corrections for PostgreSql CI tests --- .github/workflows/ezsql-linux.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 33d816da..907c0ffe 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -31,17 +31,15 @@ jobs: - name: Start PostgreSql run: | sudo systemctl start postgresql.service - sudo -u postgres createuser -P -s -e runner + pg_isready + - name: Create additional user + run: | + sudo -u postgres psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" - name: Setup PostgreSql Database - env: - # The hostname used to communicate with the PostgreSQL service container - POSTGRES_HOST: localhost - # The default PostgreSQL port - POSTGRES_PORT: 5432 run: | - export PGPASSWORD= - psql -h localhost -U runner -c 'CREATE DATABASE ez_test;' - psql -h localhost -U runner -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" + sudo -u postgres createdb --owner=ez_test ez_test + export PGPASSWORD=ezTest + psql --username=ez_test --host=localhost --list timetable - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From adbd2c88ec91007c863c7d6783c99a34645c7c3b Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 19:33:34 -0500 Subject: [PATCH 021/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 907c0ffe..4527e732 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -39,7 +39,7 @@ jobs: run: | sudo -u postgres createdb --owner=ez_test ez_test export PGPASSWORD=ezTest - psql --username=ez_test --host=localhost --list timetable + psql --username=ez_test --host=localhost --list ez_test - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance From 33253c512271983b376638807397f007ae2b4b67 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 21:06:01 -0500 Subject: [PATCH 022/148] add/fix Microsoft SQLServer setup for Linux action --- .github/install_mssql.sh | 71 +++++++++++++++++ .github/workflows/ezsql-linux.yml | 7 +- unsupported/install_sql.sh | 122 ------------------------------ 3 files changed, 73 insertions(+), 127 deletions(-) create mode 100644 .github/install_mssql.sh delete mode 100644 unsupported/install_sql.sh diff --git a/.github/install_mssql.sh b/.github/install_mssql.sh new file mode 100644 index 00000000..68797225 --- /dev/null +++ b/.github/install_mssql.sh @@ -0,0 +1,71 @@ +#!/bin/bash -e + +# Use the following variables to control your install: + +# Password for the SA user (required) +MSSQL_SA_PASSWORD='!Passw0rd' + +# Product ID of the version of SQL server you're installing +# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key +# Defaults to developer +MSSQL_PID='evaluation' + +# Install SQL Server Agent (recommended) +SQL_INSTALL_AGENT='y' + +# Install SQL Server Full Text Search (optional) +# SQL_INSTALL_FULLTEXT='y' + +# Create an additional user with sysadmin privileges (optional) +SQL_INSTALL_USER='ez_test' +SQL_INSTALL_USER_PASSWORD='ezTest' +SQL_INSTALL_DATABASE='ez_test' + +if [ -z $MSSQL_SA_PASSWORD ] +then + echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install + exit 1 +fi + +echo Adding Microsoft repositories... +sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - +repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)" +sudo add-apt-repository "${repoargs}" + +echo Running apt-get update -y... +sudo apt-get update + +echo Installing SQL Server... +sudo apt-get install -y mssql-server + +echo Running mssql-conf setup... +sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \ + MSSQL_PID=$MSSQL_PID \ + /opt/mssql/bin/mssql-conf -n setup accept-eula + +# Configure firewall to allow TCP port 1433: +echo Configuring UFW to allow traffic on port 1433... +sudo ufw allow 1433/tcp +sudo ufw reload + +# Restart SQL Server after installing: +echo Restarting SQL Server... +sudo systemctl restart mssql-server + +# Optional new user creation: +if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ] +then + echo Creating user $SQL_INSTALL_USER + sqlcmd \ + -S localhost \ + -U SA \ + -P $MSSQL_SA_PASSWORD \ + -Q "CREATE DATABASE ez_test" + sqlcmd \ + -S localhost \ + -U SA \ + -P $MSSQL_SA_PASSWORD \ + -Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[$SQL_INSTALL_DATABASE], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]" +fi + +echo Done! diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 4527e732..95ad5267 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -42,11 +42,8 @@ jobs: psql --username=ez_test --host=localhost --list ez_test - name: Setup SQLServer Database run: | - # MSSQLLocalDB is the default SQL LocalDB instance - SqlLocalDB start MSSQLLocalDB - SqlLocalDB info MSSQLLocalDB - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh" + "${GITHUB_WORKSPACE}/.github/install_mssql.sh" - name: Install dependencies run: composer install --no-progress - name: Test with phpunit diff --git a/unsupported/install_sql.sh b/unsupported/install_sql.sh deleted file mode 100644 index e2ad2acb..00000000 --- a/unsupported/install_sql.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/bash -e - -# Use the following variables to control your install: - -# Password for the SA user (required) -MSSQL_SA_PASSWORD='MasterTest' - -# Product ID of the version of SQL server you're installing -# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key -# Defaults to developer -MSSQL_PID='evaluation' - -# Install SQL Server Agent (recommended) -SQL_INSTALL_AGENT='y' - -# Install SQL Server Full Text Search (optional) -# SQL_INSTALL_FULLTEXT='y' - -# Create an additional user with sysadmin privileges (optional) -SQL_INSTALL_USER='ez_test' -SQL_INSTALL_USER_PASSWORD='ezTest' - -if [ -z $MSSQL_SA_PASSWORD ] -then - echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install - exit 1 -fi - -echo Adding Microsoft repositories... -sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - -repoargs="$(curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)" -sudo add-apt-repository "${repoargs}" -repoargs="$(curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list)" -sudo add-apt-repository "${repoargs}" - -echo Running apt-get update -y... -sudo apt-get update -y - -echo Installing SQL Server... -sudo apt-get install -y mssql-server - -echo Running mssql-conf setup... -sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \ - MSSQL_PID=$MSSQL_PID \ - /opt/mssql/bin/mssql-conf -n setup accept-eula - -echo Installing mssql-tools and unixODBC developer... -sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev - -# Add SQL Server tools to the path by default: -echo Adding SQL Server tools to your path... -echo PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bash_profile -echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - -# Optional SQL Server Agent installation: -if [ ! -z $SQL_INSTALL_AGENT ] -then - echo Installing SQL Server Agent... - sudo apt-get install -y mssql-server-agent -fi - -# Optional SQL Server Full Text Search installation: -if [ ! -z $SQL_INSTALL_FULLTEXT ] -then - echo Installing SQL Server Full-Text Search... - sudo apt-get install -y mssql-server-fts -fi - -# Configure firewall to allow TCP port 1433: -echo Configuring UFW to allow traffic on port 1433... -sudo ufw allow 1433/tcp -sudo ufw reload - -# Optional example of post-installation configuration. -# Trace flags 1204 and 1222 are for deadlock tracing. -# echo Setting trace flags... -# sudo /opt/mssql/bin/mssql-conf traceflag 1204 1222 on - -# Restart SQL Server after installing: -echo Restarting SQL Server... -sudo systemctl restart mssql-server - -# Connect to server and get the version: -counter=1 -errstatus=1 -while [ $counter -le 5 ] && [ $errstatus = 1 ] -do - echo Waiting for SQL Server to start... - sleep 3s - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "SELECT @@VERSION" 2>/dev/null - errstatus=$? - ((counter++)) -done - -# Display error if connection failed: -if [ $errstatus = 1 ] -then - echo Cannot connect to SQL Server, installation aborted - exit $errstatus -fi - -# Optional new user creation: -if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ] -then - echo Creating user $SQL_INSTALL_USER - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=ON, CHECK_POLICY=ON; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]" - /opt/mssql-tools/bin/sqlcmd \ - -S localhost \ - -U SA \ - -P $MSSQL_SA_PASSWORD \ - -Q "CREATE DATABASE ez_test" -fi - -echo Done! From adcaa2da467f339860cd6ba0772f347790d3e01d Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 21:32:51 -0500 Subject: [PATCH 023/148] Update install_mssql.sh --- .github/install_mssql.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/install_mssql.sh b/.github/install_mssql.sh index 68797225..64b19baa 100644 --- a/.github/install_mssql.sh +++ b/.github/install_mssql.sh @@ -29,11 +29,12 @@ fi echo Adding Microsoft repositories... sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - +sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)" sudo add-apt-repository "${repoargs}" echo Running apt-get update -y... -sudo apt-get update +sudo apt-get update -y echo Installing SQL Server... sudo apt-get install -y mssql-server From f905231132f246b28315e9a6044f2cc74585c458 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 22:02:14 -0500 Subject: [PATCH 024/148] Update ezsql-linux.yml --- .github/workflows/ezsql-linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 95ad5267..d666c23d 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -45,8 +45,8 @@ jobs: chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh" "${GITHUB_WORKSPACE}/.github/install_mssql.sh" - name: Install dependencies - run: composer install --no-progress + run: composer update - name: Test with phpunit - run: vendor/bin/phpunit --coverage-clover + run: vendor/bin/phpunit --coverage-clover=coverage.xml - name: Submit code coverage run: bash <(curl -s https://codecov.io/bash) From 247fc386ab376316a9b2a4143556459b8fa943f8 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 3 Feb 2021 22:28:43 -0500 Subject: [PATCH 025/148] Update composer.json --- composer.json | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 97cd7f08..29f7ef48 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,25 @@ { "name": "ezsql/ezsql", "description": "Advance database access library. Make interacting with a database ridiculously easy.", - "keywords": ["mysql", "mysqli", "postgresql", "mssql", "sqlsrv", "sqlserver", "pdo", "sqlite", "sqlite3", "database", "abstraction", "sql", "dba"], - "license": ["LGPL-3.0-or-later", "MIT"], + "keywords": [ + "mysql", + "mysqli", + "postgresql", + "mssql", + "sqlsrv", + "sqlserver", + "pdo", + "sqlite", + "sqlite3", + "database", + "abstraction", + "sql", + "dba" + ], + "license": [ + "LGPL-3.0-or-later", + "MIT" + ], "authors": [ { "name": "Justin Vincent", @@ -21,7 +38,7 @@ "issues": "https://github.com/ezSQL/ezSQL/issues" }, "require": { - "php": "^7.1", + "php": "^7.1 || ^8", "psr/container": "^1.0" }, "provide": { From adc680f17f5d4819e1f17ca632b9c698ed241b43 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 09:54:47 -0500 Subject: [PATCH 026/148] Corrections, start bug fixes for PHP 8, add Windows Github Actions CI --- .github/workflows/ezsql-linux.yml | 2 +- .github/workflows/ezsql-windows.yml | 51 +++++++++++++++++++++++++++++ lib/Database.php | 11 ++++--- lib/Database/ez_mysqli.php | 4 +-- tests/EZTestCase.php | 2 +- 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/ezsql-windows.yml diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index d666c23d..f01da5c3 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -1,5 +1,5 @@ # GitHub Action for PHP with extensions -name: ezsql-linux +name: Linux on: [push, pull_request] diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml new file mode 100644 index 00000000..57f74c96 --- /dev/null +++ b/.github/workflows/ezsql-windows.yml @@ -0,0 +1,51 @@ +# GitHub Action for PHP with extensions +name: Windows + +on: [push, pull_request] + +jobs: + windows: + name: Windows (PHP ${{ matrix.php-versions }} CI) + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + operating-system: [windows-latest] + php-versions: ['7.1', '7.2', '7.4', '8.0'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + coverage: xdebug + - name: Start MySQL + run: sudo systemctl start mysql.service + - name: Setup MySQL Database + run: | + mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Setup PostgreSql Database + run: | + psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" + createdb --owner=ez_test ez_test + SET PGPASSWORD=ezTest + psql --username=ez_test --host=localhost --list ez_test + - name: Setup SQLServer Database + run: | + # MSSQLLocalDB is the default SQL LocalDB instance + SqlLocalDB start MSSQLLocalDB + SqlLocalDB info MSSQLLocalDB + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + - name: Install dependencies + run: composer update + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Submit code coverage + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml # optional diff --git a/lib/Database.php b/lib/Database.php index b5126084..4825311d 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -18,11 +18,14 @@ class Database private static $instances = []; private function __construct() - { } + { + } private function __clone() - { } - private function __wakeup() - { } + { + } + public function __wakeup() + { + } /** * Initialize and connect a vendor database. diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 16b9326b..3ff0edd9 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -18,7 +18,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var object */ private $dbh; @@ -137,7 +137,7 @@ public function select($name = '', $charset = '') if (!$this->dbh) { // Must have an active database connection $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); - } elseif (!\mysqli_select_db($this->dbh, $name)) { + } elseif (!@\mysqli_select_db($this->dbh, $name)) { // Try to connect to the database // Try to get error supplied by mysql if not use our own if (!$str = \mysqli_error($this->dbh)) { diff --git a/tests/EZTestCase.php b/tests/EZTestCase.php index d0e81728..3600f46c 100644 --- a/tests/EZTestCase.php +++ b/tests/EZTestCase.php @@ -42,7 +42,7 @@ abstract class EZTestCase extends \PHPUnit\Framework\TestCase protected $errors; - public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) + public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext = null) { $this->errors[] = compact("errno", "errstr", "errfile", "errline", "errcontext"); } From cab0e0aa06dc7ae9a18cf8c369b4ec5f3768f0fa Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 15:47:14 -0500 Subject: [PATCH 027/148] More bug fixes for PHP 8, corrections, and code cleanup --- .github/workflows/ezsql-windows.yml | 2 - lib/Database/ez_mysqli.php | 2 +- lib/Database/ez_pdo.php | 2 +- lib/ezsqlModel.php | 72 +++++++++++++++++++++++++++-- lib/ezsqlModelInterface.php | 65 -------------------------- tests/pdo/pdo_mysqlTest.php | 2 +- 6 files changed, 71 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 57f74c96..90b5ee38 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -22,8 +22,6 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug - - name: Start MySQL - run: sudo systemctl start mysql.service - name: Setup MySQL Database run: | mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 3ff0edd9..652db783 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -225,7 +225,7 @@ private function fetch_prepared_result(&$stmt, $query) } // Binds variables to a prepared statement for result storage - \call_user_func_array([$stmt, 'bind_result'], $variables); + \call_user_func_array([$stmt, 'bind_result'], \array_values($variables)); $i = 0; // Store Query Results diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 8b80dbb4..b77a6c76 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -19,7 +19,7 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var object */ private $dbh; diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 93710198..603fb48b 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -174,9 +174,73 @@ public function __construct() } /** - * Use for Calling Non-Existent Functions, handling Getters and Setters + * Magic methods for Calling Non-Existent Functions, handling Getters and Setters. * @method set/get{property} - a property that needs to be accessed * + * @method void setDebug_All($args); + * @method void setTrace($args); + * @method void setDebug_Called($args); + * @method void setVarDump_Called($args); + * @method void setShow_Errors($args); + * @method void setNum_Queries($args); + * @method void setConn_Queries($args); + * @method void setCaptured_Errors($args); + * @method void setCache_Dir($args); + * @method void setUse_Disk_Cache($args); + * @method void setCache_Timeout($args); + * @method void setCache_Queries($args); + * @method void setCache_Inserts($args); + * @method void setNum_Rows($args); + * @method void setDb_Connect_Time($args); + * @method void setSql_Log_File($args); + * @method void setProfile_Times($args); + * @method void setInsert_Id($args); + * @method void setLast_Query($args); + * @method void setLast_Error($args); + * @method void setCol_Info($args); + * @method void setTimers($args); + * @method void setTotal_Query_Time($args); + * @method void setTrace_Log($args); + * @method void setUse_Trace_Log($args); + * @method void setDo_Profile($args); + * @method void setLast_Result($args); + * @method void setFrom_Disk_Cache($args); + * @method void setDebug_Echo_Is_On($args); + * @method void setFunc_Call($args); + * @method void setAll_Func_Calls($args); + * + * @method string getDebug_All(); + * @method string getTrace(); + * @method string getDebug_Called(); + * @method string getVarDump_Called(); + * @method string getShow_Errors(); + * @method string getNum_Queries(); + * @method string getConn_Queries(); + * @method string getCaptured_Errors(); + * @method string getCache_Dir(); + * @method string getUse_Disk_Cache(); + * @method string getCache_Timeout(); + * @method string getCache_Queries(); + * @method string getCache_Inserts(); + * @method string getNum_Rows(); + * @method string getDb_Connect_Time(); + * @method string getSql_Log_File(); + * @method string getProfile_Times(); + * @method string getInsert_Id(); + * @method string getLast_Query(); + * @method string getLast_Error(); + * @method string getCol_Info(); + * @method string getTimers(); + * @method string getTotal_Query_Time(); + * @method string getTrace_Log(); + * @method string getUse_Trace_Log(); + * @method string getDo_Profile(); + * @method string getLast_Result(); + * @method string getFrom_Disk_Cache(); + * @method string getDebug_Echo_Is_On(); + * @method string getFunc_Call(); + * @method string getAll_Func_Calls(); + * * @property-read function * @property-write args * @@ -258,8 +322,8 @@ public function flush() // Get rid of these $this->last_result = null; $this->col_info = array(); - $this->last_query = null; - $this->all_func_calls = array(); + $this->last_query = null; + $this->all_func_calls = array(); $this->from_disk_cache = false; $this->clearPrepare(); } @@ -337,7 +401,7 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa return $new_array; } - public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) + public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_results(\"$query\", $output, $use_prepare)"); diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 74b8be79..171e5f26 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -2,71 +2,6 @@ namespace ezsql; -/** - * @method void setDebug_All($args); - * @method void setTrace($args); - * @method void setDebug_Called($args); - * @method void setVarDump_Called($args); - * @method void setShow_Errors($args); - * @method void setNum_Queries($args); - * @method void setConn_Queries($args); - * @method void setCaptured_Errors($args); - * @method void setCache_Dir($args); - * @method void setUse_Disk_Cache($args); - * @method void setCache_Timeout($args); - * @method void setCache_Queries($args); - * @method void setCache_Inserts($args); - * @method void setNum_Rows($args); - * @method void setDb_Connect_Time($args); - * @method void setSql_Log_File($args); - * @method void setProfile_Times($args); - * @method void setInsert_Id($args); - * @method void setLast_Query($args); - * @method void setLast_Error($args); - * @method void setCol_Info($args); - * @method void setTimers($args); - * @method void setTotal_Query_Time($args); - * @method void setTrace_Log($args); - * @method void setUse_Trace_Log($args); - * @method void setDo_Profile($args); - * @method void setLast_Result($args); - * @method void setFrom_Disk_Cache($args); - * @method void setDebug_Echo_Is_On($args); - * @method void setFunc_Call($args); - * @method void setAll_Func_Calls($args); - * - * @method string getDebug_All(); - * @method string getTrace(); - * @method string getDebug_Called(); - * @method string getVarDump_Called(); - * @method string getShow_Errors(); - * @method string getNum_Queries(); - * @method string getConn_Queries(); - * @method string getCaptured_Errors(); - * @method string getCache_Dir(); - * @method string getUse_Disk_Cache(); - * @method string getCache_Timeout(); - * @method string getCache_Queries(); - * @method string getCache_Inserts(); - * @method string getNum_Rows(); - * @method string getDb_Connect_Time(); - * @method string getSql_Log_File(); - * @method string getProfile_Times(); - * @method string getInsert_Id(); - * @method string getLast_Query(); - * @method string getLast_Error(); - * @method string getCol_Info(); - * @method string getTimers(); - * @method string getTotal_Query_Time(); - * @method string getTrace_Log(); - * @method string getUse_Trace_Log(); - * @method string getDo_Profile(); - * @method string getLast_Result(); - * @method string getFrom_Disk_Cache(); - * @method string getDebug_Echo_Is_On(); - * @method string getFunc_Call(); - * @method string getAll_Func_Calls(); - */ interface ezsqlModelInterface { /** diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index a46f2a2a..73619325 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -16,7 +16,7 @@ class pdo_mysqlTest extends EZTestCase const TEST_DB_PORT = '3306'; /** - * @var resource + * @var object */ protected $object; From 6c15bebf354de0634b3ce321f0166f8722eae629 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 17:06:37 -0500 Subject: [PATCH 028/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 90b5ee38..7b3c23d0 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -24,8 +24,8 @@ jobs: coverage: xdebug - name: Setup MySQL Database run: | - mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;" - mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + mysql -u root -p"root" -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -p"root" -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" From 477cf44da7859607eaa8a597b141914112350f56 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 18:57:24 -0500 Subject: [PATCH 029/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 7b3c23d0..e8ad823f 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -24,10 +24,20 @@ jobs: coverage: xdebug - name: Setup MySQL Database run: | + mysqld --install + net start mysql mysql -u root -p"root" -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -u root -p"root" -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | + $postgreSqlSvc = Get-Service "postgresql*" + Set-Service $postgreSqlSvc.Name -StartupType manual + $postgreSqlSvc.Start() + try { + (Get-Service "postgresql*").Start() + } catch { + $_ | select * + } psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test SET PGPASSWORD=ezTest @@ -42,7 +52,7 @@ jobs: - name: Install dependencies run: composer update - name: Test with phpunit - run: vendor/bin/phpunit --coverage-clover=coverage.xml + run: vendor\bin\phpunit --coverage-clover=coverage.xml - name: Submit code coverage uses: codecov/codecov-action@v1 with: From baa79f9e1b8f4e2e610598326f414dcf802eeea7 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 21:03:06 -0500 Subject: [PATCH 030/148] github actions updates --- .github/workflows/ezsql-linux.yml | 8 +++++++- .github/workflows/ezsql-windows.yml | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index f01da5c3..eecfdeea 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -1,7 +1,13 @@ # GitHub Action for PHP with extensions name: Linux -on: [push, pull_request] +on: + push: + branches: + - v5 + pull_request: + branches: + - v5 jobs: linux: diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index e8ad823f..ab5a1137 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -1,7 +1,13 @@ # GitHub Action for PHP with extensions name: Windows -on: [push, pull_request] +on: + push: + branches: + - v5 + pull_request: + branches: + - v5 jobs: windows: @@ -22,12 +28,15 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug + - name: Chocolatey Install MySQL + run: choco install mysql -y -f - name: Setup MySQL Database run: | + mysqladmin --host=localhost --user=root --password=Password12! create ez_test mysqld --install net start mysql - mysql -u root -p"root" -e "CREATE DATABASE IF NOT EXISTS ez_test;" - mysql -u root -p"root" -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + mysql -u root -p"Password12!" -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -p"Password12!" -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | $postgreSqlSvc = Get-Service "postgresql*" @@ -38,6 +47,8 @@ jobs: } catch { $_ | select * } + SET PGUSER=postgres + SET PGPASSWORD=root psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test SET PGPASSWORD=ezTest From b55739f1195eda58c27e010285c003ca04c17997 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 21:59:47 -0500 Subject: [PATCH 031/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index ab5a1137..90aa05fa 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -29,14 +29,11 @@ jobs: extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug - name: Chocolatey Install MySQL - run: choco install mysql -y -f + run: choco install mysql -y - name: Setup MySQL Database run: | - mysqladmin --host=localhost --user=root --password=Password12! create ez_test - mysqld --install - net start mysql - mysql -u root -p"Password12!" -e "CREATE DATABASE IF NOT EXISTS ez_test;" - mysql -u root -p"Password12!" -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | $postgreSqlSvc = Get-Service "postgresql*" From 1ed1fe062d731940b7d51b8acc8157d31fbcf49f Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 22:07:57 -0500 Subject: [PATCH 032/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 90aa05fa..5b339fce 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -29,7 +29,7 @@ jobs: extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug - name: Chocolatey Install MySQL - run: choco install mysql -y + run: choco install mysql --version=5.7.18 -y -f - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From d8b760848b9a38190a5309fe8e2948d08fd41393 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 22:28:03 -0500 Subject: [PATCH 033/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 5b339fce..49e17f60 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -36,14 +36,10 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - $postgreSqlSvc = Get-Service "postgresql*" - Set-Service $postgreSqlSvc.Name -StartupType manual - $postgreSqlSvc.Start() - try { - (Get-Service "postgresql*").Start() - } catch { - $_ | select * - } + PATH=C:\Program Files\PostgreSQL\13\bin\;%PATH% + SET PGBIN=C:\Program Files\PostgreSQL\13\bin + SET PGDATA=C:\Program Files\PostgreSQL\13\data + SET PGROOT=C:\Program Files\PostgreSQL\13 SET PGUSER=postgres SET PGPASSWORD=root psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" From 23be3e5396a2c0f739e93b2a0e2b92c51f81ec32 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 4 Feb 2021 22:52:29 -0500 Subject: [PATCH 034/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 49e17f60..74358fb6 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -36,10 +36,10 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - PATH=C:\Program Files\PostgreSQL\13\bin\;%PATH% - SET PGBIN=C:\Program Files\PostgreSQL\13\bin - SET PGDATA=C:\Program Files\PostgreSQL\13\data - SET PGROOT=C:\Program Files\PostgreSQL\13 + PATH="C:\Program Files\PostgreSQL\13\bin\";%PATH% + SET PGBIN="C:\Program Files\PostgreSQL\13\bin" + SET PGDATA="C:\Program Files\PostgreSQL\13\data" + SET PGROOT="C:\Program Files\PostgreSQL\13" SET PGUSER=postgres SET PGPASSWORD=root psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" From e5746608677cc737144811b22f660e8ac1ca389b Mon Sep 17 00:00:00 2001 From: "L. Stubbs" Date: Fri, 5 Feb 2021 09:37:31 -0500 Subject: [PATCH 035/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 74358fb6..e894c3c1 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -36,7 +36,7 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - PATH="C:\Program Files\PostgreSQL\13\bin\";%PATH% + SET PATH="C:\Program Files\PostgreSQL\13\bin\";%PATH% SET PGBIN="C:\Program Files\PostgreSQL\13\bin" SET PGDATA="C:\Program Files\PostgreSQL\13\data" SET PGROOT="C:\Program Files\PostgreSQL\13" From 648bdb1c8352e34594147de480535b2f5b216e66 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 13:37:07 -0500 Subject: [PATCH 036/148] fixes for PHP 8, update Windows Github Action --- .github/workflows/ezsql-windows.yml | 3 ++- lib/Database/ez_mysqli.php | 4 ++-- lib/Database/ez_pdo.php | 11 ++++++++--- tests/pdo/pdo_mysqlTest.php | 2 ++ tests/pdo/pdo_pgsqlTest.php | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index e894c3c1..1f3d0782 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -36,7 +36,7 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Setup PostgreSql Database run: | - SET PATH="C:\Program Files\PostgreSQL\13\bin\";%PATH% + $env:Path += ";C:\Program Files\PostgreSQL\13\bin" SET PGBIN="C:\Program Files\PostgreSQL\13\bin" SET PGDATA="C:\Program Files\PostgreSQL\13\data" SET PGROOT="C:\Program Files\PostgreSQL\13" @@ -46,6 +46,7 @@ jobs: createdb --owner=ez_test ez_test SET PGPASSWORD=ezTest psql --username=ez_test --host=localhost --list ez_test + [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Setup SQLServer Database run: | # MSSQLLocalDB is the default SQL LocalDB instance diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 652db783..65cfe064 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -134,10 +134,10 @@ public function select($name = '', $charset = '') { $this->_connected = false; $name = empty($name) ? $this->database->getName() : $name; - if (!$this->dbh) { + if (!$this->dbh || !\mysqli_ping($this->dbh)) { // Must have an active database connection $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); - } elseif (!@\mysqli_select_db($this->dbh, $name)) { + } elseif (!\mysqli_select_db($this->dbh, $name)) { // Try to connect to the database // Try to get error supplied by mysql if not use our own if (!$str = \mysqli_error($this->dbh)) { diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index b77a6c76..58001519 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -239,7 +239,7 @@ public function query_prepared(string $query, array $param = null, $isSelect = f { $stmt = $this->dbh->prepare($query); $result = false; - if ($stmt && $stmt->execute($param)) { + if ($stmt && $stmt->execute(\array_values($param))) { $result = $stmt->rowCount(); // Store Query Results $num_rows = 0; @@ -346,8 +346,13 @@ private function processQuery(string $query, array $param = null) if (!empty($param) && \is_array($param) && $this->isPrepareOn()) { $this->shortcutUsed = true; $this->_affectedRows = $this->query_prepared($query, $param, false); - } else - $this->_affectedRows = $this->dbh->exec($query); + } else { + try { + $this->_affectedRows = $this->dbh->exec($query); + } catch (\Exception $ex) { + // + } + } if ($this->processResult($query) === false) return false; diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index 73619325..663b9766 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -323,6 +323,7 @@ public function testJoins() public function testBeginTransactionCommit() { $this->object->connect(); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $commit = null; @@ -355,6 +356,7 @@ public function testBeginTransactionCommit() public function testBeginTransactionRollback() { $this->object->connect(); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $commit = null; diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 58a91eb1..209037c2 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -18,7 +18,7 @@ class pdo_pgsqlTest extends EZTestCase const TEST_SQLITE_DB = 'ez_test.sqlite'; /** - * @var resource + * @var object */ protected $object; From c95d250cd4098a7f4f01a8528ad48d56413aca58 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 13:51:34 -0500 Subject: [PATCH 037/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 1f3d0782..7a338e59 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -37,11 +37,10 @@ jobs: - name: Setup PostgreSql Database run: | $env:Path += ";C:\Program Files\PostgreSQL\13\bin" - SET PGBIN="C:\Program Files\PostgreSQL\13\bin" - SET PGDATA="C:\Program Files\PostgreSQL\13\data" - SET PGROOT="C:\Program Files\PostgreSQL\13" SET PGUSER=postgres SET PGPASSWORD=root + initdb -D "C:\Program Files\PostgreSQL\13\data" + pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test SET PGPASSWORD=ezTest From fc842cedad68ff609712acf38ef6e591c01100f6 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 16:18:35 -0500 Subject: [PATCH 038/148] Update ez_mysqli.php for PHP 8 bug, CI corrections --- .github/workflows/ezsql-windows.yml | 3 -- lib/Database/ez_mysqli.php | 52 ++++++++++++++++------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 7a338e59..14f15a3d 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -39,12 +39,9 @@ jobs: $env:Path += ";C:\Program Files\PostgreSQL\13\bin" SET PGUSER=postgres SET PGPASSWORD=root - initdb -D "C:\Program Files\PostgreSQL\13\data" pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test - SET PGPASSWORD=ezTest - psql --username=ez_test --host=localhost --list ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Setup SQLServer Database run: | diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 65cfe064..1913dbac 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -134,35 +134,41 @@ public function select($name = '', $charset = '') { $this->_connected = false; $name = empty($name) ? $this->database->getName() : $name; - if (!$this->dbh || !\mysqli_ping($this->dbh)) { - // Must have an active database connection - $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); - } elseif (!\mysqli_select_db($this->dbh, $name)) { + try { // Try to connect to the database - // Try to get error supplied by mysql if not use our own - if (!$str = \mysqli_error($this->dbh)) { - $str = 'Unexpected error while trying to select database'; - } - $this->register_error($str . ' in ' . __FILE__ . ' on line ' . __LINE__); - } else { - $this->database->setName($name); - if ($charset == '') { - $charset = $this->database->getCharset(); - } + if (\mysqli_select_db($this->dbh, $name)) { + $this->database->setName($name); + if ( + $charset == '' + ) { + $charset = $this->database->getCharset(); + } - if ($charset != '') { - $encoding = \strtolower(\str_replace('-', '', $charset)); - $charsetArray = array(); - $recordSet = \mysqli_query($this->dbh, 'SHOW CHARACTER SET'); - while ($row = \mysqli_fetch_array($recordSet, \MYSQLI_ASSOC)) { - $charsetArray[] = $row['Charset']; + if ($charset != '') { + $encoding = \strtolower(\str_replace('-', '', $charset)); + $charsetArray = array(); + $recordSet = \mysqli_query($this->dbh, 'SHOW CHARACTER SET'); + while ($row = \mysqli_fetch_array($recordSet, \MYSQLI_ASSOC)) { + $charsetArray[] = $row['Charset']; + } + + if (\in_array($charset, $charsetArray)) { + \mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\''); + } } - if (\in_array($charset, $charsetArray)) { - \mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\''); + $this->_connected = true; + } + } catch (\Exception $e) { + $str = \FAILED_CONNECTION; + // Must have an active database connection + if ($this->dbh) { + // Try to get error supplied by mysql if not use our own + if (!$str = \mysqli_error($this->dbh)) { + $str = 'Unexpected error while trying to select database'; } } - $this->_connected = true; + $this->register_error($str . ' in ' . __FILE__ . ' on line ' . __LINE__); } return $this->_connected; From 29c0d2b45060008132c0d63c294fce8da831b9d7 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 19:22:37 -0500 Subject: [PATCH 039/148] updates/bug fixes --- .github/workflows/ezsql-linux.yml | 2 -- .github/workflows/ezsql-windows.yml | 7 +++--- lib/Database/ez_mysqli.php | 38 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index eecfdeea..8ae0e606 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -44,8 +44,6 @@ jobs: - name: Setup PostgreSql Database run: | sudo -u postgres createdb --owner=ez_test ez_test - export PGPASSWORD=ezTest - psql --username=ez_test --host=localhost --list ez_test - name: Setup SQLServer Database run: | chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh" diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 14f15a3d..520def33 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -40,7 +40,7 @@ jobs: SET PGUSER=postgres SET PGPASSWORD=root pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" + psql -u postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Setup SQLServer Database @@ -48,8 +48,9 @@ jobs: # MSSQLLocalDB is the default SQL LocalDB instance SqlLocalDB start MSSQLLocalDB SqlLocalDB info MSSQLLocalDB - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "EXEC sp_password NULL, 'Password12!', 'sa';" + sqlcmd -S "(localdb)\MSSQLLocalDB" -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 1913dbac..16104f87 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -136,30 +136,30 @@ public function select($name = '', $charset = '') $name = empty($name) ? $this->database->getName() : $name; try { // Try to connect to the database - if (\mysqli_select_db($this->dbh, $name)) { - $this->database->setName($name); - if ( - $charset == '' - ) { - $charset = $this->database->getCharset(); - } + if (($this->dbh == null) || !\mysqli_select_db($this->dbh, $name)) { + throw new Exception("Error Processing Request", 1); + } - if ($charset != '') { - $encoding = \strtolower(\str_replace('-', '', $charset)); - $charsetArray = array(); - $recordSet = \mysqli_query($this->dbh, 'SHOW CHARACTER SET'); - while ($row = \mysqli_fetch_array($recordSet, \MYSQLI_ASSOC)) { - $charsetArray[] = $row['Charset']; - } + $this->database->setName($name); + if ($charset == '') { + $charset = $this->database->getCharset(); + } - if (\in_array($charset, $charsetArray)) { - \mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\''); - } + if ($charset != '') { + $encoding = \strtolower(\str_replace('-', '', $charset)); + $charsetArray = array(); + $recordSet = \mysqli_query($this->dbh, 'SHOW CHARACTER SET'); + while ($row = \mysqli_fetch_array($recordSet, \MYSQLI_ASSOC)) { + $charsetArray[] = $row['Charset']; } - $this->_connected = true; + if (\in_array($charset, $charsetArray)) { + \mysqli_query($this->dbh, 'SET NAMES \'' . $encoding . '\''); + } } - } catch (\Exception $e) { + + $this->_connected = true; + } catch (Exception $e) { $str = \FAILED_CONNECTION; // Must have an active database connection if ($this->dbh) { From d885176e65216b1678a55f9bbf1ecd05e229196f Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 20:05:48 -0500 Subject: [PATCH 040/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 520def33..497034ae 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -37,10 +37,10 @@ jobs: - name: Setup PostgreSql Database run: | $env:Path += ";C:\Program Files\PostgreSQL\13\bin" - SET PGUSER=postgres - SET PGPASSWORD=root + $env:PGUSER=postgres + $env:PGPASSWORD=root pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start - psql -u postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" + psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Setup SQLServer Database From 4fdcb5c196193dc4740c31e914622ffc0d9652ff Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 20:17:39 -0500 Subject: [PATCH 041/148] testing --- .github/workflows/ezsql-windows.yml | 5 ++--- tests/mysqli/mysqliTest.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 497034ae..5a92944c 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -37,9 +37,8 @@ jobs: - name: Setup PostgreSql Database run: | $env:Path += ";C:\Program Files\PostgreSQL\13\bin" - $env:PGUSER=postgres - $env:PGPASSWORD=root - pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start + $env:PGUSER = "postgres" + $env:PGPASSWORD = "root" psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 87618173..40d2f367 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -90,7 +90,7 @@ public function testSelect() $this->assertTrue($result); $this->errors = array(); - set_error_handler(array($this, 'errorHandler')); + //set_error_handler(array($this, 'errorHandler')); $this->assertTrue($this->object->select('')); $this->object->disconnect(); $this->assertFalse($this->object->select('notest')); From d1d310aaa3f18fcb4d559c6e79f59f2bb881f3f5 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 20:46:12 -0500 Subject: [PATCH 042/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 5a92944c..b59b9d23 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -39,7 +39,9 @@ jobs: $env:Path += ";C:\Program Files\PostgreSQL\13\bin" $env:PGUSER = "postgres" $env:PGPASSWORD = "root" - psql -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" + initdb -D "C:\Program Files\PostgreSQL\13\data" + pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start + psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Setup SQLServer Database From 82c121ade0839f3d10ec16a55c3c25c9325b8884 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 21:37:56 -0500 Subject: [PATCH 043/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index b59b9d23..c80016b5 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -49,9 +49,8 @@ jobs: # MSSQLLocalDB is the default SQL LocalDB instance SqlLocalDB start MSSQLLocalDB SqlLocalDB info MSSQLLocalDB - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "EXEC sp_password NULL, 'Password12!', 'sa';" - sqlcmd -S "(localdb)\MSSQLLocalDB" -U sa -P Password12! -Q "CREATE DATABASE ez_test" - sqlcmd -S "(localdb)\MSSQLLocalDB" -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" + sqlcmd -S "(localdb)\MSSQLLocalDB" -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit From 3d59176d5a291d9e46fe39711e1512b95cf01dc1 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 22:23:26 -0500 Subject: [PATCH 044/148] php 8 fixes --- lib/DInjector.php | 4 +++- lib/ezQuery.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/DInjector.php b/lib/DInjector.php index f24e8c13..b34bbb64 100644 --- a/lib/DInjector.php +++ b/lib/DInjector.php @@ -129,7 +129,9 @@ protected function getDependencies($parameters, $values = null) if (\is_array($parameters)) { foreach ($parameters as $parameter) { // get the type hinted class - $dependency = $parameter->getClass(); + $dependency = $parameter->getType() && !$parameter->getType()->isBuiltin() + ? new \ReflectionClass($parameter->getType()->getName()) + : NULL; if ($dependency === NULL) { // check if the constructor parameter name exists as a key in the values array if (\array_key_exists($parameter->getName(), $values)) { diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 7c02ac73..b94c4336 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -723,7 +723,7 @@ public function delete(string $table = null, ...$whereConditions) * Helper does the actual insert or replace query with an array * @return mixed bool/results - false for error */ - private function _query_insert_replace($table = '', $keyAndValue, $type = '', $execute = true) + private function _query_insert_replace($table = '', $keyAndValue = null, $type = '', $execute = true) { if ((!\is_array($keyAndValue) && ($execute)) || empty($table)) { return $this->clearPrepare(); From 18938b26236ff79e67538072631d51135cc538ab Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 5 Feb 2021 23:43:59 -0500 Subject: [PATCH 045/148] Update ez_mysqli.php --- lib/Database/ez_mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 16104f87..c2d776f2 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -159,7 +159,7 @@ public function select($name = '', $charset = '') } $this->_connected = true; - } catch (Exception $e) { + } catch (\Throwable $e) { $str = \FAILED_CONNECTION; // Must have an active database connection if ($this->dbh) { From ae6189583e7bd327c220bc403704b23d2269c9b7 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 08:01:44 -0500 Subject: [PATCH 046/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index c80016b5..52fd9f2a 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -50,7 +50,8 @@ jobs: SqlLocalDB start MSSQLLocalDB SqlLocalDB info MSSQLLocalDB sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" - sqlcmd -S "(localdb)\MSSQLLocalDB" -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + EXEC sp_addlogin 'ez_test', 'ezTest', 'ez_test' + sqlcmd -S "(localdb)\MSSQLLocalDB" -d ez_test -Q "ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit From fc89914336c4e019802fae51ba6c6b8f67cd6035 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 09:37:13 -0500 Subject: [PATCH 047/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 52fd9f2a..68f911db 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -50,7 +50,7 @@ jobs: SqlLocalDB start MSSQLLocalDB SqlLocalDB info MSSQLLocalDB sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" - EXEC sp_addlogin 'ez_test', 'ezTest', 'ez_test' + sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "EXEC sp_addlogin 'ez_test', 'ezTest', 'ez_test'" sqlcmd -S "(localdb)\MSSQLLocalDB" -d ez_test -Q "ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update From 19b995afef8615640fe677ac2d7f9a5882c3e9ea Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 11:35:17 -0500 Subject: [PATCH 048/148] Update ez_mysqli.php --- lib/Database/ez_mysqli.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index c2d776f2..08fc12e5 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -132,11 +132,12 @@ public function connect( */ public function select($name = '', $charset = '') { + $status = $this->_connected; $this->_connected = false; $name = empty($name) ? $this->database->getName() : $name; try { // Try to connect to the database - if (($this->dbh == null) || !\mysqli_select_db($this->dbh, $name)) { + if (($this->dbh === null) || ($status === false) || !\mysqli_select_db($this->dbh, $name)) { throw new Exception("Error Processing Request", 1); } From e0d5d7366bd44e97b8b00d24978a48e9a03d1277 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 12:14:45 -0500 Subject: [PATCH 049/148] refactor for PHP 8, should only be called when on a active open connection, and not change state --- lib/Database/ez_mysqli.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 08fc12e5..97145727 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -132,12 +132,10 @@ public function connect( */ public function select($name = '', $charset = '') { - $status = $this->_connected; - $this->_connected = false; $name = empty($name) ? $this->database->getName() : $name; try { // Try to connect to the database - if (($this->dbh === null) || ($status === false) || !\mysqli_select_db($this->dbh, $name)) { + if (($this->dbh === null) || ($this->_connected === false) || !\mysqli_select_db($this->dbh, $name)) { throw new Exception("Error Processing Request", 1); } @@ -159,7 +157,7 @@ public function select($name = '', $charset = '') } } - $this->_connected = true; + return true; } catch (\Throwable $e) { $str = \FAILED_CONNECTION; // Must have an active database connection @@ -169,10 +167,10 @@ public function select($name = '', $charset = '') $str = 'Unexpected error while trying to select database'; } } + $this->register_error($str . ' in ' . __FILE__ . ' on line ' . __LINE__); + return false; } - - return $this->_connected; } // select /** From 1a5cff95ac448dd2d8d9ff8583193e2941a35a07 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 12:51:23 -0500 Subject: [PATCH 050/148] ez_mysql fixes for PHP 8, user mssqlserver2014express in CI for Windows SQLServer --- .github/workflows/ezsql-windows.yml | 10 ++++------ lib/Database/ez_mysqli.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 68f911db..86a4b1d1 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -44,14 +44,12 @@ jobs: psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) + - name: Chocolatey Install SQLServer + run: choco install mssqlserver2014express -y -f - name: Setup SQLServer Database run: | - # MSSQLLocalDB is the default SQL LocalDB instance - SqlLocalDB start MSSQLLocalDB - SqlLocalDB info MSSQLLocalDB - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "CREATE DATABASE ez_test" - sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "EXEC sp_addlogin 'ez_test', 'ezTest', 'ez_test'" - sqlcmd -S "(localdb)\MSSQLLocalDB" -d ez_test -Q "ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 97145727..bbf2f621 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -161,7 +161,7 @@ public function select($name = '', $charset = '') } catch (\Throwable $e) { $str = \FAILED_CONNECTION; // Must have an active database connection - if ($this->dbh) { + if ($this->dbh && $this->_connected) { // Try to get error supplied by mysql if not use our own if (!$str = \mysqli_error($this->dbh)) { $str = 'Unexpected error while trying to select database'; From 1510f904b86b54cae70dd82059db5908451adbed Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 13:34:54 -0500 Subject: [PATCH 051/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 86a4b1d1..547bf3e7 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -45,11 +45,14 @@ jobs: createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Chocolatey Install SQLServer - run: choco install mssqlserver2014express -y -f + run: | + choco install mssqlserver2014express -y -f + refreshenv - name: Setup SQLServer Database run: | - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" - sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + sqlcmd -S localhost -Q "EXEC sp_password NULL, 'Password12!', 'sa';" + sqlcmd -S localhost -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S localhost -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit From 2ee08c55ddf90d4655bd9975cdf148bb0762dfb5 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 13:48:01 -0500 Subject: [PATCH 052/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 547bf3e7..464bb77f 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -45,9 +45,9 @@ jobs: createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Chocolatey Install SQLServer - run: | - choco install mssqlserver2014express -y -f - refreshenv + run: choco install mssqlserver2014express -y -f + - name: Chocolatey refresh + run: refreshenv - name: Setup SQLServer Database run: | sqlcmd -S localhost -Q "EXEC sp_password NULL, 'Password12!', 'sa';" From c7ab869d75062f7091cc401be6ad9a542b1baeb7 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 14:50:05 -0500 Subject: [PATCH 053/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 464bb77f..cb40e7a3 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -46,8 +46,6 @@ jobs: [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Chocolatey Install SQLServer run: choco install mssqlserver2014express -y -f - - name: Chocolatey refresh - run: refreshenv - name: Setup SQLServer Database run: | sqlcmd -S localhost -Q "EXEC sp_password NULL, 'Password12!', 'sa';" From d6e23a730bda8b3598bbc92898cfbf28fbfab6cb Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 15:17:43 -0500 Subject: [PATCH 054/148] corrections --- .github/workflows/ezsql-windows.yml | 1 + tests/pdo/pdo_mysqlTest.php | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index cb40e7a3..fb7ce6a2 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -48,6 +48,7 @@ jobs: run: choco install mssqlserver2014express -y -f - name: Setup SQLServer Database run: | + sqlcmd -L -E -S . sqlcmd -S localhost -Q "EXEC sp_password NULL, 'Password12!', 'sa';" sqlcmd -S localhost -U sa -P Password12! -Q "CREATE DATABASE ez_test" sqlcmd -S localhost -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index 663b9766..498ed843 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -288,14 +288,15 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; From aa204b34b549b01d5eecd8daeb5a084356a01f48 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 18:37:04 -0500 Subject: [PATCH 055/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index fb7ce6a2..edbdf42b 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -45,13 +45,14 @@ jobs: createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) - name: Chocolatey Install SQLServer - run: choco install mssqlserver2014express -y -f + run: choco install sql-server-express -ia "/IACCEPTSQLSERVERLICENSETERMS /Q /ACTION=install /INSTANCEID=MSSQLSERVER /INSTANCENAME=MSSQLSERVER /UPDATEENABLED=FALSE /TCPENABLED=1 /SECURITYMODE=SQL /SAPWD=Password12!" -o -y -f - name: Setup SQLServer Database run: | - sqlcmd -L -E -S . - sqlcmd -S localhost -Q "EXEC sp_password NULL, 'Password12!', 'sa';" - sqlcmd -S localhost -U sa -P Password12! -Q "CREATE DATABASE ez_test" - sqlcmd -S localhost -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + sqlcmd -L + New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow + New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow + sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit From f038b39473f45ea4e04558f9354a86dc18a30e1d Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 19:49:14 -0500 Subject: [PATCH 056/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index edbdf42b..640eafc1 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -34,13 +34,11 @@ jobs: run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Chocolatey Install PostgreSql By Force + run: choco install postgresql13 --params '/Password:root' --ia '--serverport 5433' -y -f - name: Setup PostgreSql Database run: | - $env:Path += ";C:\Program Files\PostgreSQL\13\bin" - $env:PGUSER = "postgres" - $env:PGPASSWORD = "root" - initdb -D "C:\Program Files\PostgreSQL\13\data" - pg_ctl -D "C:\Program Files\PostgreSQL\13\data" -l logfile start + $env:PGPASSWORD = "root"; '\conninfo' | psql -Upostgres psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) From 7cfa6a025d3579ba40ec8129f0b4c15b0bfc183d Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 20:23:14 -0500 Subject: [PATCH 057/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 640eafc1..b01a47ff 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -34,8 +34,8 @@ jobs: run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - - name: Chocolatey Install PostgreSql By Force - run: choco install postgresql13 --params '/Password:root' --ia '--serverport 5433' -y -f + - name: Chocolatey Install PostgreSql 9 By Force + run: choco install postgresql9 --params '/Password:root' --ia '--serverport 5433' -y -f - name: Setup PostgreSql Database run: | $env:PGPASSWORD = "root"; '\conninfo' | psql -Upostgres From 91fcec454200fa848dc71990c7fab1872b78c14f Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 20:52:32 -0500 Subject: [PATCH 058/148] Update ezsql-windows.yml --- .github/workflows/ezsql-windows.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index b01a47ff..557cbdfa 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -38,7 +38,9 @@ jobs: run: choco install postgresql9 --params '/Password:root' --ia '--serverport 5433' -y -f - name: Setup PostgreSql Database run: | - $env:PGPASSWORD = "root"; '\conninfo' | psql -Upostgres + $env:Path += ";C:\Program Files\PostgreSQL\9.6\bin" + $env:PGPASSWORD = "root" + psql -U postgres --command="\conninfo" psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test [Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine) From f088a0dfc40aefe79a727c25b65ca834c702cd20 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 21:11:09 -0500 Subject: [PATCH 059/148] test's bug fixes --- tests/pdo/pdo_pgsqlTest.php | 11 ++++++++--- tests/pdo/pdo_sqliteTest.php | 9 +++++---- tests/pdo/pdo_sqlsrvTest.php | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 209037c2..842f6e44 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -192,6 +192,7 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); @@ -210,14 +211,15 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; @@ -237,6 +239,9 @@ public function testJoins() $this->assertEquals($o, $row->parent_id); --$o; } + + $this->object->query('DROP TABLE unit_test'); + $this->object->query('DROP TABLE unit_test_child'); } public function testPosgreSQLDisconnect() diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index 2cc13485..3908b7db 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -17,7 +17,7 @@ class pdo_sqliteTest extends EZTestCase const TEST_SQLITE_DB = './tests/pdo/ez_test.sqlite'; /** - * @var resource + * @var object */ protected $object; @@ -239,14 +239,15 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index de8e82bd..c2efc98c 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -8,7 +8,7 @@ class pdo_sqlsrvTest extends EZTestCase { /** - * @var resource + * @var object */ protected $object; @@ -191,6 +191,8 @@ public function testSelecting() foreach ($result as $row) { $this->assertEquals('testing 8', $row->test_key); } + + $this->object->query('DROP TABLE unit_test'); } public function testWhereGrouping() @@ -209,19 +211,22 @@ public function testWhereGrouping() $this->assertEquals('testing ' . $i, $row->test_key); $i = $i + 2; } + + $this->object->query('DROP TABLE unit_test'); } public function testJoins() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; @@ -241,6 +246,9 @@ public function testJoins() $this->assertEquals($o, $row->parent_id); --$o; } + + $this->object->query('DROP TABLE unit_test'); + $this->object->query('DROP TABLE unit_test_child'); } public function testSQLsrvDisconnect() From 1652445fff3dd445c855deeeda918d886dbfae45 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 6 Feb 2021 21:20:56 -0500 Subject: [PATCH 060/148] fixes --- .github/workflows/ezsql-windows.yml | 2 ++ tests/pdo/pdo_pgsqlTest.php | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 557cbdfa..6014c8fb 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -40,6 +40,8 @@ jobs: run: | $env:Path += ";C:\Program Files\PostgreSQL\9.6\bin" $env:PGPASSWORD = "root" + initdb -D "C:\Program Files\PostgreSQL\9.6\data" + pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start psql -U postgres --command="\conninfo" psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 842f6e44..92c0b876 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -194,10 +194,10 @@ public function testWhereGrouping() $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); + $this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1', 'active' => 1)); + $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2', 'active' => 0)); + $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3', 'active' => 1)); + $this->object->insert('unit_test', array('id' => 4, 'test_key' => 'testing 4', 'active' => 1)); $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; @@ -206,6 +206,7 @@ public function testWhereGrouping() $this->assertEquals('testing ' . $i, $row->test_key); $i = $i + 2; } + $this->object->query('DROP TABLE unit_test'); } public function testJoins() From 69aebac0e04d9b480c927069158894b09f54e9f2 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 07:55:55 -0500 Subject: [PATCH 061/148] corrections/fixes --- .github/workflows/ezsql-windows.yml | 6 ++++-- lib/Database/ez_pdo.php | 8 ++++++-- tests/pdo/pdo_pgsqlTest.php | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 6014c8fb..3a696657 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -34,8 +34,10 @@ jobs: run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - - name: Chocolatey Install PostgreSql 9 By Force - run: choco install postgresql9 --params '/Password:root' --ia '--serverport 5433' -y -f + - name: Chocolatey Uninstall PostgreSql 13 + run: choco uninstall postgresql13 -y -f + - name: Chocolatey Install PostgreSql 9 + run: choco install postgresql9 --params '/Password:root' -y -f - name: Setup PostgreSql Database run: | $env:Path += ";C:\Program Files\PostgreSQL\9.6\bin" diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 58001519..cd2bb15b 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -349,7 +349,7 @@ private function processQuery(string $query, array $param = null) } else { try { $this->_affectedRows = $this->dbh->exec($query); - } catch (\Exception $ex) { + } catch (\Throwable $ex) { // } } @@ -365,7 +365,11 @@ private function processQuery(string $query, array $param = null) $this->shortcutUsed = true; $sth = $this->query_prepared($query, $param, true); } else - $sth = $this->dbh->query($query); + try { + $sth = $this->dbh->query($query); + } catch (\Throwable $ex) { + // + } if ($this->processResult($query, $sth, true) === false) return false; diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 92c0b876..d8ec5d85 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -194,10 +194,10 @@ public function testWhereGrouping() $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->query('DROP TABLE unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => 4, 'test_key' => 'testing 4', 'active' => 1)); + $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); + $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); + $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); + $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; From 898823d0e37079c377ba084b52d3637c691a9d23 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 08:40:49 -0500 Subject: [PATCH 062/148] update/recheck --- .github/workflows/ezsql-windows.yml | 2 -- lib/Database/ez_pdo.php | 12 ++++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 3a696657..9ef4ec49 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -42,8 +42,6 @@ jobs: run: | $env:Path += ";C:\Program Files\PostgreSQL\9.6\bin" $env:PGPASSWORD = "root" - initdb -D "C:\Program Files\PostgreSQL\9.6\data" - pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start psql -U postgres --command="\conninfo" psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du" createdb --owner=ez_test ez_test diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index cd2bb15b..869371fd 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -19,7 +19,7 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var object + * @var \PDO */ private $dbh; @@ -318,9 +318,13 @@ private function processResult(string $query, $result = null, bool $isSelect = f if (!empty($result)) $this->_affectedRows = $result; - // Take note of the insert_id - if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = @$this->dbh->lastInsertId(); + try { + // Take note of the insert_id + if (\preg_match("/^(insert|replace)\s+/i", $query)) { + $this->insert_id = @$this->dbh->lastInsertId(); + } + } catch (\Throwable $ex) { + // } // Return number of rows affected From 8d717228c9efb277888134c71a76c6f3471b6b58 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 13:58:50 -0500 Subject: [PATCH 063/148] various bug fixes and updates for PHP 8 --- lib/Database.php | 1 + lib/Database/ez_mysqli.php | 2 +- lib/Database/ez_pdo.php | 12 ++++++++---- lib/Database/ez_pgsql.php | 6 +++++- lib/Database/ez_sqlite3.php | 2 +- lib/ezQuery.php | 16 +++++++++++++++- lib/ezsqlModel.php | 15 +++++++++++++++ tests/pdo/pdo_mysqlTest.php | 10 +++++----- tests/pdo/pdo_pgsqlTest.php | 16 ++++++++++------ tests/pdo/pdo_sqliteTest.php | 5 +++-- tests/pdo/pdo_sqlsrvTest.php | 26 ++++++++++++++------------ 11 files changed, 78 insertions(+), 33 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 4825311d..914d0687 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -33,6 +33,7 @@ public function __wakeup() * @param mixed $vendor - SQL driver * @param mixed $setting - SQL connection parameters * @param mixed $tag - Store the instance for later use + * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) { diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index bbf2f621..2ec89afb 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -18,7 +18,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var object + * @var \mysqli */ private $dbh; diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 869371fd..9f458df0 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -243,10 +243,14 @@ public function query_prepared(string $query, array $param = null, $isSelect = f $result = $stmt->rowCount(); // Store Query Results $num_rows = 0; - while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; - $num_rows++; + try { + while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) { + // Store results as an objects within main array + $this->last_result[$num_rows] = (object) $row; + $num_rows++; + } + } catch (\Throwable $ex) { + // } $this->num_rows = $num_rows; diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 4f56e161..e987aef7 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -298,7 +298,11 @@ public function query(string $query, bool $use_prepare = false) $this->shortcutUsed = true; $this->result = $this->query_prepared($query, $param); } else { - $this->result = @\pg_query($this->dbh, $query); + try { + $this->result = @\pg_query($this->dbh, $query); + } catch (\Throwable $ex) { + // + } } if ($this->processQueryResult($query) === false) { diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index 8c9a7f37..b7dead0e 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -18,7 +18,7 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface /** * Database connection handle - * @var resource + * @var \SQLite3 */ private $dbh; diff --git a/lib/ezQuery.php b/lib/ezQuery.php index b94c4336..88a76f5d 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -812,7 +812,15 @@ public function get_results( return array(); } - // query call template + // + + /** + * query call template + * + * @param string $query + * @param bool $use_prepare + * @return bool|mixed + */ public function query(string $query, bool $use_prepare = false) { return false; @@ -965,6 +973,12 @@ public function alter(string $table = null, ...$schemas) return false; } + /** + * Does an drop table query if table exists. + * @param $table - database table to erase + * + * @return bool + */ public function drop(string $table = null) { if (empty($table)) diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 603fb48b..6de9efc3 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -728,16 +728,31 @@ public function secureReset() $this->secureOptions = null; } + /** + * Returns `true` if the database connection is established. + * + * @return bool + */ public function isConnected() { return $this->_connected; } // isConnected + /** + * Returns the `number` of affected rows of a query. + * + * @return int + */ public function affectedRows() { return $this->_affectedRows; } // affectedRows + /** + * Returns the last query `result`. + * + * @return object + */ public function queryResult() { return $this->last_result; diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index 498ed843..a6c1c7d5 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -16,7 +16,7 @@ class pdo_mysqlTest extends EZTestCase const TEST_DB_PORT = '3306'; /** - * @var object + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -302,10 +302,10 @@ public function testJoins() $i = 1; $o = 3; foreach ($result as $row) { - $this->assertEquals($i, $row->child_id); - $this->assertEquals('testing child ' . $i, $row->child_test_key); - $this->assertEquals($o, $row->id); - $this->assertEquals('testing ' . $o, $row->test_key); + $this->assertEquals($o, $row->child_id); + $this->assertEquals('testing child ' . $o, $row->child_test_key); + $this->assertEquals($i, $row->id); + $this->assertEquals('testing ' . $i, $row->test_key); ++$i; --$o; } diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index d8ec5d85..56299f75 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -18,7 +18,7 @@ class pdo_pgsqlTest extends EZTestCase const TEST_SQLITE_DB = 'ez_test.sqlite'; /** - * @var object + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -157,6 +157,7 @@ public function testDelete() public function testSelecting() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id serial, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('test_key' => 'test 1', 'test_value' => 'testing string 1')); $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); @@ -187,12 +188,14 @@ public function testSelecting() foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } + + $this->object->drop('unit_test'); } public function testWhereGrouping() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); @@ -206,13 +209,14 @@ public function testWhereGrouping() $this->assertEquals('testing ' . $i, $row->test_key); $i = $i + 2; } - $this->object->query('DROP TABLE unit_test'); + + $this->object->drop('unit_test'); } public function testJoins() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); @@ -241,8 +245,8 @@ public function testJoins() --$o; } - $this->object->query('DROP TABLE unit_test'); - $this->object->query('DROP TABLE unit_test_child'); + $this->object->drop('unit_test'); + $this->object->drop('unit_test_child'); } public function testPosgreSQLDisconnect() diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index 3908b7db..d9644c73 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -17,7 +17,7 @@ class pdo_sqliteTest extends EZTestCase const TEST_SQLITE_DB = './tests/pdo/ez_test.sqlite'; /** - * @var object + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -219,6 +219,7 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); @@ -239,7 +240,7 @@ public function testWhereGrouping() public function testJoins() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index c2efc98c..d370887c 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -8,7 +8,7 @@ class pdo_sqlsrvTest extends EZTestCase { /** - * @var object + * @var \ezsql\Database\ez_pdo */ protected $object; @@ -89,8 +89,8 @@ public function testInsert() public function testUpdate() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); - $this->assertNotFalse($this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testUpdate() 1'))); $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testUpdate() 2')); $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testUpdate() 3')); @@ -163,6 +163,7 @@ public function testDelete() public function testSelecting() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => 8, 'test_key' => 'testing 8')); $this->object->insert('unit_test', array('id' => 9, 'test_key' => 'testing 9')); @@ -192,17 +193,18 @@ public function testSelecting() $this->assertEquals('testing 8', $row->test_key); } - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); } public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); + $this->object->drop('unit_test'); + $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); + $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active_data' => 1)); $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; @@ -212,13 +214,13 @@ public function testWhereGrouping() $i = $i + 2; } - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); } public function testJoins() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); @@ -247,8 +249,8 @@ public function testJoins() --$o; } - $this->object->query('DROP TABLE unit_test'); - $this->object->query('DROP TABLE unit_test_child'); + $this->object->drop('unit_test'); + $this->object->drop('unit_test_child'); } public function testSQLsrvDisconnect() From 653e92fc2a014693602cf12c7632153d8068ea49 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 15:23:27 -0500 Subject: [PATCH 064/148] corrections for PHP 8, split CI tests for platform PHP versions --- .github/workflows/ezsql-linux.yml | 2 +- .github/workflows/ezsql-windows.yml | 2 +- lib/Database/ez_pdo.php | 12 ++++++++---- lib/Database/ez_pgsql.php | 10 +++++++--- lib/Database/ez_sqlsrv.php | 6 +++++- tests/sqlsrv/sqlsrvTest.php | 2 +- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 8ae0e606..89337f3d 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.1', '7.2', '7.4', '8.0'] + php-versions: ['7.2', '7.4', '8.0'] steps: - name: Checkout diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 9ef4ec49..1ea10a60 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [windows-latest] - php-versions: ['7.1', '7.2', '7.4', '8.0'] + php-versions: ['7.1', '7.3', '8.0'] steps: - name: Checkout diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 9f458df0..f3790581 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -304,10 +304,14 @@ private function processResult(string $query, $result = null, bool $isSelect = f // Store Query Results $num_rows = 0; - while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; - $num_rows++; + try { + while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) { + // Store results as an objects within main array + $this->last_result[$num_rows] = (object) $row; + $num_rows++; + } + } catch (\Throwable $ex) { + // } // Log number of rows the query returned diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index e987aef7..3d5eed8c 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -162,9 +162,13 @@ private function processQueryResult(string $query, $result = null) if (!empty($result)) $this->result = $result; - // If there is an error then take note of it.. - if ($str = @\pg_last_error($this->dbh)) { - return $this->register_error($str); + try { + // If there is an error then take note of it.. + if ($str = @\pg_last_error($this->dbh)) { + return $this->register_error($str); + } + } catch (\Throwable $ex) { + return $this->register_error($ex->getMessage()); } // Query was an insert, delete, update, replace diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index ccfe5806..8685772f 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -300,7 +300,11 @@ public function query(string $query, bool $use_prepare = false) $this->shortcutUsed = true; $this->result = $this->query_prepared($query, $param); } else { - $this->result = @\sqlsrv_query($this->dbh, $query); + try { + $this->result = @\sqlsrv_query($this->dbh, $query); + } catch (\Throwable $ex) { + // + } } if ($this->processQueryResult($query) === false) { diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index 21d1f682..cd9bc926 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -37,7 +37,7 @@ protected function setUp(): void */ protected function tearDown(): void { - $this->object->query('DROP TABLE unit_test'); + $this->object->drop('unit_test'); $this->object = null; } From 86c0e0ee72a8d80d9efbb5f748319720b7aab07e Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 17:48:34 -0500 Subject: [PATCH 065/148] Update pdo_sqlsrvTest.php --- tests/pdo/pdo_sqlsrvTest.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index d370887c..482cd49f 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -199,14 +199,13 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->drop('unit_test'); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active_data' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active_data' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active_data' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active_data' => 1)); + $this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1)); - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->selecting('unit_test', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); From d91024562ff058c44845d4eaa298c4875dbc8227 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 7 Feb 2021 23:23:02 -0500 Subject: [PATCH 066/148] fixes for php 8 --- lib/Database/ez_sqlsrv.php | 94 +++++++++++++++++++----------------- tests/pdo/pdo_pgsqlTest.php | 18 +++---- tests/pdo/pdo_sqlsrvTest.php | 14 +++--- tests/sqlsrv/sqlsrvTest.php | 6 +-- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index 8685772f..154f260f 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -179,61 +179,65 @@ private function processQueryResult(string $query, $result = null) // Query was an insert, delete, update, replace $this->is_insert = false; - if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { - $this->is_insert = true; - $this->_affectedRows = @\sqlsrv_rows_affected($this->result); - - // Take note of the insert_id - if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $identityResultset = @\sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()"); - - if ($identityResultset != false) { - $identityRow = @\sqlsrv_fetch($identityResultset); - $this->insert_id = $identityRow[0]; + try { + if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { + $this->is_insert = true; + $this->_affectedRows = @\sqlsrv_rows_affected($this->result); + + // Take note of the insert_id + if (\preg_match("/^(insert|replace)\s+/i", $query)) { + $identityResultset = @\sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()"); + + if ($identityResultset != false) { + $identityRow = @\sqlsrv_fetch($identityResultset); + $this->insert_id = $identityRow[0]; + } } - } - // Return number of rows affected - $this->return_val = $this->_affectedRows; - } else { // Query was a select - // Take note of column info - $i = 0; - foreach (@\sqlsrv_field_metadata($this->result) as $field) { - $col = []; - foreach ($field as $name => $value) { - $name = \strtolower($name); - if ($name == "size") { - $name = "max_length"; - } elseif ($name == "type") { - $name = "typeid"; + // Return number of rows affected + $this->return_val = $this->_affectedRows; + } else { // Query was a select + // Take note of column info + $i = 0; + foreach (@\sqlsrv_field_metadata($this->result) as $field) { + $col = []; + foreach ($field as $name => $value) { + $name = \strtolower($name); + if ($name == "size") { + $name = "max_length"; + } elseif ($name == "type") { + $name = "typeid"; + } + + //DEFINED FOR E_STRICT + $col = new \stdClass(); + $col->{$name} = $value; } - //DEFINED FOR E_STRICT - $col = new \stdClass(); - $col->{$name} = $value; + $col->type = $this->get_datatype($col); + $this->col_info[$i++] = $col; + unset($col); } - $col->type = $this->get_datatype($col); - $this->col_info[$i++] = $col; - unset($col); - } - - // Store Query Results - $num_rows = 0; + // Store Query Results + $num_rows = 0; - while ($row = @\sqlsrv_fetch_object($this->result)) { + while ($row = @\sqlsrv_fetch_object($this->result)) { - // Store results as an objects within main array - $this->last_result[$num_rows] = $row; - $num_rows++; - } + // Store results as an objects within main array + $this->last_result[$num_rows] = $row; + $num_rows++; + } - @\sqlsrv_free_stmt($this->result); + @\sqlsrv_free_stmt($this->result); - // Log number of rows the query returned - $this->num_rows = $num_rows; + // Log number of rows the query returned + $this->num_rows = $num_rows; - // Return number of rows selected - $this->return_val = $this->num_rows; + // Return number of rows selected + $this->return_val = $this->num_rows; + } + } catch (\Throwable $ex) { + return false; } return $this->return_val; diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 56299f75..fc4562bc 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -195,14 +195,14 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->drop('unit_test'); - $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0)); - $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); - $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); - - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $this->object->drop('unit_test_more'); + $this->object->query('CREATE TABLE unit_test_more(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); + $this->object->insert('unit_test_more', array('id' => '1', 'test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('id' => '2', 'test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test_more', array('id' => '3', 'test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('id' => '4', 'test_key' => 'testing 4', 'active_data' => 1)); + + $result = $this->object->selecting('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -210,7 +210,7 @@ public function testWhereGrouping() $i = $i + 2; } - $this->object->drop('unit_test'); + $this->object->drop('unit_test_more'); } public function testJoins() diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index 482cd49f..2351b979 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -199,13 +199,13 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1)); - $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0)); - $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); - $this->object->insert('unit_test', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1)); + $this->object->query('CREATE TABLE unit_test_other(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); + $this->object->insert('unit_test_other', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test_other', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test_other', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test_other', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1)); - $result = $this->object->selecting('unit_test', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->selecting('unit_test_other', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -213,7 +213,7 @@ public function testWhereGrouping() $i = $i + 2; } - $this->object->drop('unit_test'); + $this->object->drop('unit_test_other'); } public function testJoins() diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index cd9bc926..04df061f 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -363,9 +363,9 @@ public function testQuery_prepared() column('prepare_key', VARCHAR, 50) ); - $this->object->insert('prepare_test', ['id' => 1, 'prepare_key' => 'test 2']); - $this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']); - $this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [1, 'test 2']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']); + $this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']); $this->object->query_prepared('SELECT id, prepare_key FROM prepare_test WHERE id = ?', [9]); $query = $this->object->queryResult(); From fea351f02f2677356ca2773551741d777d941661 Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 8 Feb 2021 00:17:44 -0500 Subject: [PATCH 067/148] Update pdo_pgsqlTest.php --- tests/pdo/pdo_pgsqlTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index fc4562bc..70780444 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -196,11 +196,11 @@ public function testWhereGrouping() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->drop('unit_test_more'); - $this->object->query('CREATE TABLE unit_test_more(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); - $this->object->insert('unit_test_more', array('id' => '1', 'test_key' => 'testing 1', 'active_data' => 1)); - $this->object->insert('unit_test_more', array('id' => '2', 'test_key' => 'testing 2', 'active_data' => 0)); - $this->object->insert('unit_test_more', array('id' => '3', 'test_key' => 'testing 3', 'active_data' => 1)); - $this->object->insert('unit_test_more', array('id' => '4', 'test_key' => 'testing 4', 'active_data' => 1)); + $this->object->query('CREATE TABLE unit_test_more(id serial, test_key varchar(50), active_data integer, PRIMARY KEY (ID))'); + $this->object->insert('unit_test_more', array('test_key' => 'testing 1', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 2', 'active_data' => 0)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 3', 'active_data' => 1)); + $this->object->insert('unit_test_more', array('test_key' => 'testing 4', 'active_data' => 1)); $result = $this->object->selecting('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; From d107a52e900b8ac951b78266ac803d7f0aae23dd Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 8 Feb 2021 09:49:41 -0500 Subject: [PATCH 068/148] Update pdo_sqlsrvTest.php --- tests/pdo/pdo_sqlsrvTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index 2351b979..58619195 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -199,7 +199,7 @@ public function testSelecting() public function testWhereGrouping() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); - $this->object->query('CREATE TABLE unit_test_other(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))'); + $this->object->query('CREATE TABLE unit_test_other(id integer, test_key varchar(50), active_data integer, PRIMARY KEY (ID))'); $this->object->insert('unit_test_other', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1)); $this->object->insert('unit_test_other', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0)); $this->object->insert('unit_test_other', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); From 3d0c0aeeb7a1b264dd7dab8b7b9d17fc812e9cbe Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 8 Feb 2021 11:08:32 -0500 Subject: [PATCH 069/148] Add branch badges, update Github Action build matrix --- .github/workflows/ezsql-linux.yml | 2 +- .github/workflows/ezsql-windows.yml | 2 +- README.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 89337f3d..797a4ddb 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.4', '8.0'] + php-versions: ['7.1', '7.3', '8.0'] steps: - name: Checkout diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 1ea10a60..e3c66dc4 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [windows-latest] - php-versions: ['7.1', '7.3', '8.0'] + php-versions: ['7.2', '7.4'] steps: - name: Checkout diff --git a/README.md b/README.md index 526839bf..8a1a4782 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # **ezsql** -[![Build Status](https://travis-ci.org/ezSQL/ezsql.svg?branch=master)](https://travis-ci.org/ezSQL/ezsql) -[![Build status](https://ci.appveyor.com/api/projects/status/6s8oqnoxa2i5k04f?svg=true)](https://ci.appveyor.com/project/jv2222/ezsql) +[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg?branch=v5)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows) +[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg?branch=v5)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux) [![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aad1f6aaaaa14f60933e75615da900b8)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com&utm_medium=referral&utm_content=ezSQL/ezsql&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability) From 7e1330aeb4d23dea117411e3c0462078e696822f Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 8 Feb 2021 11:44:51 -0500 Subject: [PATCH 070/148] update --- .github/workflows/ezsql-linux.yml | 2 +- .github/workflows/ezsql-windows.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 797a4ddb..8307b931 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.1', '7.3', '8.0'] + php-versions: ['7.2', '8.0'] steps: - name: Checkout diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index e3c66dc4..4334ea1e 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [windows-latest] - php-versions: ['7.2', '7.4'] + php-versions: ['7.4'] steps: - name: Checkout From 733fc21b831db348876f71413f540c42d55beca3 Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 8 Feb 2021 12:33:38 -0500 Subject: [PATCH 071/148] workaround for CI systems various config issues for build errors --- .github/workflows/ezsql-linux.yml | 2 +- .github/workflows/ezsql-windows.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 8307b931..67d8b81e 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '8.0'] + php-versions: ['7.4', '8.0'] steps: - name: Checkout diff --git a/.github/workflows/ezsql-windows.yml b/.github/workflows/ezsql-windows.yml index 4334ea1e..388d4b8a 100644 --- a/.github/workflows/ezsql-windows.yml +++ b/.github/workflows/ezsql-windows.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [windows-latest] - php-versions: ['7.4'] + php-versions: ['7.1', '7.2'] steps: - name: Checkout From a7120f7b75e5c4283d7427006b763b55793f2751 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 16:00:53 -0500 Subject: [PATCH 072/148] Create ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/ezsql-macos.yml diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml new file mode 100644 index 00000000..fd5f1ece --- /dev/null +++ b/.github/workflows/ezsql-macos.yml @@ -0,0 +1,70 @@ +# GitHub Action for PHP with extensions +name: macOS + +on: + push: + branches: + - v5 + pull_request: + branches: + - v5 + +jobs: + windows: + name: macOS (PHP ${{ matrix.php-versions }} CI) + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + operating-system: [macos-latest] + php-versions: ['7.3'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + coverage: xdebug + - name: Brew Install MySQL + run: brew install mysql@5.7 + - name: Brew Start MySQL + run: | + brew services start mysql@5.7 + brew link mysql@5.7 --force + mysqld --initialize + mysql -V + - name: Setup MySQL Database + run: | + mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + - name: Brew Start PostgreSql + run: brew services restart postgresql + - name: Setup PostgreSql Database + run: | + psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" + createdb --owner=ez_test ez_test + - name: Docker Install SQLServer + run: | + docker pull mcr.microsoft.com/mssql/server:2019-latest + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server:2019-latest + - name: Brew Install ODBC 17 and MSSQL Tools + run: | + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release + brew update + HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install mssql-tools + - name: Setup SQLServer Database + run: | + sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" + sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" + - name: Install dependencies + run: composer update + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Submit code coverage + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml # optional From 52a4ec9b1ae645d558be85dca6eb2691abddbbf3 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 16:13:42 -0500 Subject: [PATCH 073/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index fd5f1ece..35832b6f 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -29,13 +29,15 @@ jobs: extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug coverage: xdebug - name: Brew Install MySQL - run: brew install mysql@5.7 + run: | + brew install mysql@5.7 + mkdir /usr/local/var/mysql + chmod 777 mkdir /usr/local/var/mysql + brew postinstall mysql@5.7 - name: Brew Start MySQL run: | brew services start mysql@5.7 brew link mysql@5.7 --force - mysqld --initialize - mysql -V - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From a7f900bfe927cde6b0de30235adee390f79a0a82 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 16:27:50 -0500 Subject: [PATCH 074/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 35832b6f..482c2b24 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -31,13 +31,11 @@ jobs: - name: Brew Install MySQL run: | brew install mysql@5.7 - mkdir /usr/local/var/mysql - chmod 777 mkdir /usr/local/var/mysql - brew postinstall mysql@5.7 - name: Brew Start MySQL run: | brew services start mysql@5.7 brew link mysql@5.7 --force + mysqld --initialize-insecure - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From 14d577dd1543421d18edfc018499786a7b92accc Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 20:13:30 -0500 Subject: [PATCH 075/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 482c2b24..8eb71586 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -33,7 +33,11 @@ jobs: brew install mysql@5.7 - name: Brew Start MySQL run: | + mkdir -p /usr/local/var/mysql + mkdir /var/mysql + brew doctor brew services start mysql@5.7 + ln -s /tmp/mysql.sock /var/mysql/mysql.sock brew link mysql@5.7 --force mysqld --initialize-insecure - name: Setup MySQL Database From cb49703d0e6f3f4031e139b068dfbe4398de2522 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 20:21:56 -0500 Subject: [PATCH 076/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 8eb71586..99cdf69d 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -34,10 +34,10 @@ jobs: - name: Brew Start MySQL run: | mkdir -p /usr/local/var/mysql - mkdir /var/mysql + sudo mkdir /var/mysql brew doctor brew services start mysql@5.7 - ln -s /tmp/mysql.sock /var/mysql/mysql.sock + sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock brew link mysql@5.7 --force mysqld --initialize-insecure - name: Setup MySQL Database From d9ccbe32d3b7d28d4bf091210328a84a918784a0 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 20:27:48 -0500 Subject: [PATCH 077/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 99cdf69d..43989ef3 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -35,7 +35,6 @@ jobs: run: | mkdir -p /usr/local/var/mysql sudo mkdir /var/mysql - brew doctor brew services start mysql@5.7 sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock brew link mysql@5.7 --force From 4f11d2904b717bde7da747e9ba414e4805299882 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 20:38:38 -0500 Subject: [PATCH 078/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 43989ef3..ff246c2e 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -33,9 +33,8 @@ jobs: brew install mysql@5.7 - name: Brew Start MySQL run: | - mkdir -p /usr/local/var/mysql - sudo mkdir /var/mysql brew services start mysql@5.7 + sudo ls /var/mysql/ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock brew link mysql@5.7 --force mysqld --initialize-insecure From 75a6cd568ef3dc23e490ffa2a52b0e08b5e40a94 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 20:54:20 -0500 Subject: [PATCH 079/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index ff246c2e..10147ddf 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -34,10 +34,10 @@ jobs: - name: Brew Start MySQL run: | brew services start mysql@5.7 - sudo ls /var/mysql/ - sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock brew link mysql@5.7 --force mysqld --initialize-insecure + sudo ls /var/ + sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From ef3586065f34160ff74ace8bea6d8713d244af61 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 21:05:38 -0500 Subject: [PATCH 080/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 10147ddf..5d5f1a55 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,8 +36,9 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /var/ - sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock + sudo ls /var/spool/ + sudo ls /usr/local/var/mysql/ + sudo ln -s /tmp/mysql.sock /usr/local/var/mysql/mysql.sock - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From f6e284443a35c2cf7ad4acb777e8afb556dce05c Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 21:27:13 -0500 Subject: [PATCH 081/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 5d5f1a55..9dc59726 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,13 +36,11 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /var/spool/ - sudo ls /usr/local/var/mysql/ - sudo ln -s /tmp/mysql.sock /usr/local/var/mysql/mysql.sock + sudo ls /usr/local/var/mysql/mysql/ - name: Setup MySQL Database run: | - mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" - mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + mysql -u root -h127.0.0.1 -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -h127.0.0.1 -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql run: brew services restart postgresql - name: Setup PostgreSql Database From d656e905bd6edf5675d4a891259b81b2ad4b0e36 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 21:43:42 -0500 Subject: [PATCH 082/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 9dc59726..72b71769 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,11 +36,12 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /usr/local/var/mysql/mysql/ + sudo ls /etc/ + sudo cat /etc/my.cnf - name: Setup MySQL Database run: | - mysql -u root -h127.0.0.1 -e "CREATE DATABASE IF NOT EXISTS ez_test;" - mysql -u root -h127.0.0.1 -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" + mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" + mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql run: brew services restart postgresql - name: Setup PostgreSql Database From 1781b28bc288c4d3dd72adde78a7405fd832c27a Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 22:02:00 -0500 Subject: [PATCH 083/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 72b71769..268f8d4e 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,8 +36,8 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /etc/ - sudo cat /etc/my.cnf + sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/ + sudo cat /usr/local/Cellar/mysql@5.7/5.7.32/my.cnf - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From b44a48aeed6f7082ac4cf71f875a6ec9e203432b Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 22:13:17 -0500 Subject: [PATCH 084/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 268f8d4e..306a036e 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,8 +36,14 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/ - sudo cat /usr/local/Cellar/mysql@5.7/5.7.32/my.cnf + sudo ls /usr/local/Cellar/mysql@5.7/ + echo '-----' + sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/share/ + echo '-----' + sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/bin/ + echo '-----' + sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/lib/ + mysql --help - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From e164ac61ae8b54ffdd2f7c799a9646ad8c3cc6c6 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 22:24:43 -0500 Subject: [PATCH 085/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 306a036e..b2c21693 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,13 +36,12 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - sudo ls /usr/local/Cellar/mysql@5.7/ echo '-----' - sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/share/ + sudo ls /usr/local/var/ echo '-----' - sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/bin/ + sudo ls /usr/local/etc/ echo '-----' - sudo ls /usr/local/Cellar/mysql@5.7/5.7.32/lib/ + sudo cat /usr/local/etc/my.cnf mysql --help - name: Setup MySQL Database run: | From a80aea9a09e4237a07d6c3127e50e62789ee00c5 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 22:33:02 -0500 Subject: [PATCH 086/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index b2c21693..f1eb2342 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -37,11 +37,11 @@ jobs: brew link mysql@5.7 --force mysqld --initialize-insecure echo '-----' - sudo ls /usr/local/var/ + sudo ls /usr/local/var/mysql/ echo '-----' - sudo ls /usr/local/etc/ + sudo ls /usr/local/var/run/ echo '-----' - sudo cat /usr/local/etc/my.cnf + sudo ls /var/run/ mysql --help - name: Setup MySQL Database run: | From ad5a129a2e96d6b7b6bfe8761c08dc1e8cd823b4 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 22:42:30 -0500 Subject: [PATCH 087/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index f1eb2342..edb20f81 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -36,13 +36,9 @@ jobs: brew services start mysql@5.7 brew link mysql@5.7 --force mysqld --initialize-insecure - echo '-----' - sudo ls /usr/local/var/mysql/ - echo '-----' - sudo ls /usr/local/var/run/ + mysql.server start echo '-----' sudo ls /var/run/ - mysql --help - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" From 9b7476e97180ce62a479e006d8d5fb3fbfe0416c Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 9 Feb 2021 23:17:14 -0500 Subject: [PATCH 088/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index edb20f81..10d897c4 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -37,17 +37,17 @@ jobs: brew link mysql@5.7 --force mysqld --initialize-insecure mysql.server start - echo '-----' - sudo ls /var/run/ - name: Setup MySQL Database run: | mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;" mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql - run: brew services restart postgresql + run: | + brew services restart postgresql + pg_isready - name: Setup PostgreSql Database run: | - psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" + psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - name: Docker Install SQLServer run: | From 8d8da8e02e959170ebb64db7144f4e43f0b3e553 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 09:50:25 -0500 Subject: [PATCH 089/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 10d897c4..3a7bbfe2 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -43,8 +43,7 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql run: | - brew services restart postgresql - pg_isready + brew services start postgresql - name: Setup PostgreSql Database run: | psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" From b334e9502fd04a0c678c9c490fa0b32fb9ef5630 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 10:42:46 -0500 Subject: [PATCH 090/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 3a7bbfe2..43028977 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -43,7 +43,11 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql run: | - brew services start postgresql + rm /usr/local/var/postgres/postmaster.pid + sudo mkdir /var/pgsql_socket/ + sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/ + pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start + brew services restart postgresql - name: Setup PostgreSql Database run: | psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" From 7f7511e521cff45570817e7071579c66597b7913 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 10:52:28 -0500 Subject: [PATCH 091/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 43028977..2685da32 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -43,13 +43,13 @@ jobs: mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;" - name: Brew Start PostgreSql run: | - rm /usr/local/var/postgres/postmaster.pid sudo mkdir /var/pgsql_socket/ sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start brew services restart postgresql - name: Setup PostgreSql Database run: | + createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - name: Docker Install SQLServer From 9057b3b5c8d9909bfc6a71162f9db66a3519f82d Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 11:22:37 -0500 Subject: [PATCH 092/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 2685da32..d1b4e3e3 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -52,10 +52,14 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test + - name: Install docker + run: | + brew install docker docker-machine docker-compose + sudo docker –version - name: Docker Install SQLServer run: | - docker pull mcr.microsoft.com/mssql/server:2019-latest - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server:2019-latest + docker pull mcr.microsoft.com/mssql/server + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server - name: Brew Install ODBC 17 and MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 47027213e8ed70fc1cb49311b01b18470fbb07b9 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:06:02 -0500 Subject: [PATCH 093/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index d1b4e3e3..ce8fc0d2 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,8 +54,7 @@ jobs: createdb --owner=ez_test ez_test - name: Install docker run: | - brew install docker docker-machine docker-compose - sudo docker –version + brew install docker - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From 14e4e5c744e0efbc2a4257e5eb7c02536c42f29f Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:19:25 -0500 Subject: [PATCH 094/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index ce8fc0d2..e1496603 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,7 +54,9 @@ jobs: createdb --owner=ez_test ez_test - name: Install docker run: | - brew install docker + brew install docker docker-machine + docker version + sudo dockerd - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From 05841bfc9456100161faa4565e6c9b912229d1ee Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:31:21 -0500 Subject: [PATCH 095/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index e1496603..c9eff8e9 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -55,7 +55,8 @@ jobs: - name: Install docker run: | brew install docker docker-machine - docker version + brew services start docker-machine + brew services start docker sudo dockerd - name: Docker Install SQLServer run: | From 049bd6e34edcb46ee66df4e6c6b139df7380ab98 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:39:30 -0500 Subject: [PATCH 096/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index c9eff8e9..d2e08569 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -56,6 +56,7 @@ jobs: run: | brew install docker docker-machine brew services start docker-machine + docker-machine env default brew services start docker sudo dockerd - name: Docker Install SQLServer From 21649baad09a71df0a32e870e177bc3e9fdbc220 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:46:35 -0500 Subject: [PATCH 097/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index d2e08569..97b55c30 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -56,7 +56,7 @@ jobs: run: | brew install docker docker-machine brew services start docker-machine - docker-machine env default + docker-machine ls brew services start docker sudo dockerd - name: Docker Install SQLServer From 9d96794fac984b6f067d7a3a7a5c9f88002b6595 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 12:55:38 -0500 Subject: [PATCH 098/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 97b55c30..1b3df736 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -56,8 +56,6 @@ jobs: run: | brew install docker docker-machine brew services start docker-machine - docker-machine ls - brew services start docker sudo dockerd - name: Docker Install SQLServer run: | From 0160749402e8429c9a51347843ca16eee39bad68 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 13:10:49 -0500 Subject: [PATCH 099/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 1b3df736..8def5a5e 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -52,11 +52,15 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - - name: Install docker + - name: Install Docker, Docker Machine, and Virtualbox run: | brew install docker docker-machine + brew install virtualbox --cask brew services start docker-machine - sudo dockerd + docker-machine create --driver virtualbox default + docker-machine ls + docker-machine env default + eval $(docker-machine env default) - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From 09e6e4e3481ecd833a9ebbab070043bacb830abc Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 13:53:16 -0500 Subject: [PATCH 100/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 8def5a5e..11d16265 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -52,15 +52,14 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - - name: Install Docker, Docker Machine, and Virtualbox + - name: Install Docker, and Docker Machine run: | brew install docker docker-machine brew install virtualbox --cask brew services start docker-machine docker-machine create --driver virtualbox default - docker-machine ls - docker-machine env default eval $(docker-machine env default) + sudo dockerd - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From db8ce199377534cbc9eb0c638ad5774e5a02e3d1 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 14:01:38 -0500 Subject: [PATCH 101/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 11d16265..e10cf700 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -59,7 +59,6 @@ jobs: brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) - sudo dockerd - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From aca669115d1c820df1bbc6dd16018ce558623808 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 14:11:15 -0500 Subject: [PATCH 102/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index e10cf700..5b97446f 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -59,6 +59,7 @@ jobs: brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) + docker-machine restart - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From 101f339916a50a7d73b91e88add733013c352040 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 14:50:41 -0500 Subject: [PATCH 103/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 92 ++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 5b97446f..3e0fda90 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -13,6 +13,14 @@ jobs: windows: name: macOS (PHP ${{ matrix.php-versions }} CI) runs-on: macos-latest + container: + image: mcr.microsoft.com/mssql/server + env: + ACCEPT_EULA: y + SA_PASSWORD: Password12! + ports: + - 1433:1433/tcp + - 1434:1434/tcp strategy: fail-fast: false matrix: @@ -52,14 +60,84 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - - name: Install Docker, and Docker Machine + - name: "[Pre] Install Requirements" + shell: bash run: | - brew install docker docker-machine - brew install virtualbox --cask - brew services start docker-machine - docker-machine create --driver virtualbox default - eval $(docker-machine env default) - docker-machine restart + brew install coreutils + brew install bash + brew install socat + + - name: "[Pre] Install Docker" + shell: bash + run: | + brew install docker docker-machine-driver-xhyve + sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve + sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve + while ! docker-machine create --driver xhyve default; do + docker-machine rm -f default + sleep 1; + done + # Export variable (this target) + eval "$(docker-machine env default)" + DOCKER_TLS_VERIFY="$( docker-machine env default | grep DOCKER_TLS_VERIFY | sed -e 's/.*="//g' -e 's/"$//g' )" + DOCKER_HOST="$( docker-machine env default | grep DOCKER_HOST | sed -e 's/.*="//g' -e 's/"$//g' )" + DOCKER_CERT_PATH="$( docker-machine env default | grep DOCKER_CERT_PATH | sed -e 's/.*="//g' -e 's/"$//g' )" + DOCKER_MACHINE_NAME="$( docker-machine env default | grep DOCKER_MACHINE_NAME | sed -e 's/.*="//g' -e 's/"$//g' )" + # Export variable (this other targets) + # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-environment-variable-set-env + echo ::set-env name=DOCKER_TLS_VERIFY::${DOCKER_TLS_VERIFY} + echo ::set-env name=DOCKER_HOST::${DOCKER_HOST} + echo ::set-env name=DOCKER_CERT_PATH::${DOCKER_CERT_PATH} + echo ::set-env name=DOCKER_MACHINE_NAME::${DOCKER_MACHINE_NAME} + # Show info + docker-machine ls + docker-machine env default + docker version + + - name: "[Pre] Install Docker Compose" + shell: bash + run: | + sudo curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + docker-compose version + + - name: "[Pre] Setup Docker machine" + shell: bash + run: | + # Setup DNS records + echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts + + # Portforwarding from DOCKER_HOST to local + HOST="$( echo "${DOCKER_HOST}" | sed -e 's|^tcp://||g' -e 's|:.*||g' )" + echo "${HOST}" + sudo socat -s -d -d tcp-listen:80,reuseaddr,fork tcp:${HOST}:80 & + sleep 2 + sudo socat -s -d -d tcp-listen:443,reuseaddr,fork tcp:${HOST}:443 & + sleep 2 + if ! netstat -an | grep -i LISTEN | grep -E '(:80)|(\.80)\s'; then + netstat -an | grep -i LISTEN; + false; + fi + if ! netstat -an | grep -i LISTEN | grep -E '(:443)|(\.443)\s'; then + netstat -an | grep -i LISTEN; + false; + fi + host localhost + curl -sS -I 'http://localhost:80' || true + curl -sS -I 'https://localhost:443' || true + + - name: "[Info] Show environment" + shell: bash + run: | + env + if: success() || failure() + + - name: "[Info] Show network" + shell: bash + run: | + netstat -an || true + ss -tlun || true + if: success() || failure() - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server From 496c2f4f05b5c1c1b74e62aaba7408f315dcaafb Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 14:59:57 -0500 Subject: [PATCH 104/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 3e0fda90..2c9aaba0 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -13,14 +13,6 @@ jobs: windows: name: macOS (PHP ${{ matrix.php-versions }} CI) runs-on: macos-latest - container: - image: mcr.microsoft.com/mssql/server - env: - ACCEPT_EULA: y - SA_PASSWORD: Password12! - ports: - - 1433:1433/tcp - - 1434:1434/tcp strategy: fail-fast: false matrix: @@ -141,7 +133,7 @@ jobs: - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install ODBC 17 and MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 80e0ddee4ee9800e8da26d169a73e52ae41c0201 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 15:39:05 -0500 Subject: [PATCH 105/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 86 +++---------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 2c9aaba0..6ffbeed2 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -52,88 +52,18 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - - name: "[Pre] Install Requirements" - shell: bash + - name: Install Docker, and Docker Machine run: | - brew install coreutils - brew install bash - brew install socat - - - name: "[Pre] Install Docker" - shell: bash - run: | - brew install docker docker-machine-driver-xhyve - sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve - sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve - while ! docker-machine create --driver xhyve default; do - docker-machine rm -f default - sleep 1; - done - # Export variable (this target) - eval "$(docker-machine env default)" - DOCKER_TLS_VERIFY="$( docker-machine env default | grep DOCKER_TLS_VERIFY | sed -e 's/.*="//g' -e 's/"$//g' )" - DOCKER_HOST="$( docker-machine env default | grep DOCKER_HOST | sed -e 's/.*="//g' -e 's/"$//g' )" - DOCKER_CERT_PATH="$( docker-machine env default | grep DOCKER_CERT_PATH | sed -e 's/.*="//g' -e 's/"$//g' )" - DOCKER_MACHINE_NAME="$( docker-machine env default | grep DOCKER_MACHINE_NAME | sed -e 's/.*="//g' -e 's/"$//g' )" - # Export variable (this other targets) - # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-environment-variable-set-env - echo ::set-env name=DOCKER_TLS_VERIFY::${DOCKER_TLS_VERIFY} - echo ::set-env name=DOCKER_HOST::${DOCKER_HOST} - echo ::set-env name=DOCKER_CERT_PATH::${DOCKER_CERT_PATH} - echo ::set-env name=DOCKER_MACHINE_NAME::${DOCKER_MACHINE_NAME} - # Show info - docker-machine ls - docker-machine env default - docker version - - - name: "[Pre] Install Docker Compose" - shell: bash - run: | - sudo curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - docker-compose version - - - name: "[Pre] Setup Docker machine" - shell: bash - run: | - # Setup DNS records - echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts - - # Portforwarding from DOCKER_HOST to local - HOST="$( echo "${DOCKER_HOST}" | sed -e 's|^tcp://||g' -e 's|:.*||g' )" - echo "${HOST}" - sudo socat -s -d -d tcp-listen:80,reuseaddr,fork tcp:${HOST}:80 & - sleep 2 - sudo socat -s -d -d tcp-listen:443,reuseaddr,fork tcp:${HOST}:443 & - sleep 2 - if ! netstat -an | grep -i LISTEN | grep -E '(:80)|(\.80)\s'; then - netstat -an | grep -i LISTEN; - false; - fi - if ! netstat -an | grep -i LISTEN | grep -E '(:443)|(\.443)\s'; then - netstat -an | grep -i LISTEN; - false; - fi - host localhost - curl -sS -I 'http://localhost:80' || true - curl -sS -I 'https://localhost:443' || true - - - name: "[Info] Show environment" - shell: bash - run: | - env - if: success() || failure() - - - name: "[Info] Show network" - shell: bash - run: | - netstat -an || true - ss -tlun || true - if: success() || failure() + brew install docker docker-machine + brew services start docker-machine + docker-machine create --driver virtualbox default + eval $(docker-machine env default) + docker-machine restart - name: Docker Install SQLServer run: | docker pull mcr.microsoft.com/mssql/server - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server + ls -lah /var/run/docker.sock /var/tmp/docker.sock + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server - name: Brew Install ODBC 17 and MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From c82abda94b50e665f0722f83418b3b128c3e1b6d Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 16:01:20 -0500 Subject: [PATCH 106/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 6ffbeed2..db276a58 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -61,8 +61,9 @@ jobs: docker-machine restart - name: Docker Install SQLServer run: | - docker pull mcr.microsoft.com/mssql/server - ls -lah /var/run/docker.sock /var/tmp/docker.sock + ls -lah /var/run/docker.sock /var/tmp/docker.sock /var/run/ + sudo mkdir -p /var/tmp/docker.sock + sudo ln -s /var/run/docker.sock /var/tmp/docker.sock docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server - name: Brew Install ODBC 17 and MSSQL Tools run: | From 7352e0972a1bc9a04dc489f433323d3bac56e3d5 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 18:23:03 -0500 Subject: [PATCH 107/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index db276a58..74572aaf 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -58,14 +58,14 @@ jobs: brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) - docker-machine restart - name: Docker Install SQLServer run: | - ls -lah /var/run/docker.sock /var/tmp/docker.sock /var/run/ - sudo mkdir -p /var/tmp/docker.sock - sudo ln -s /var/run/docker.sock /var/tmp/docker.sock + ls -lah /var/tmp/ + sudo mkdir -p /var/tmp/ + sudo ln -s /var/run/docker.sock /var/tmp/ + docker pull mcr.microsoft.com/mssql/server docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server - - name: Brew Install ODBC 17 and MSSQL Tools + - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release From 07ac6c96607d6798721cd60d49860606bd6f9d69 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 18:37:26 -0500 Subject: [PATCH 108/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 74572aaf..eac5e9af 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,11 +60,10 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - ls -lah /var/tmp/ - sudo mkdir -p /var/tmp/ - sudo ln -s /var/run/docker.sock /var/tmp/ + ls -lah /Users/runner/.docker/ + sudo touch /var/run/docker.sock docker pull mcr.microsoft.com/mssql/server - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -p 1434:1434 -d mcr.microsoft.com/mssql/server + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 8c290fdd048546d8e9f07ae27b188b9dc01f0bef Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 19:08:38 -0500 Subject: [PATCH 109/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index eac5e9af..733cce9c 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,8 +60,8 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - ls -lah /Users/runner/.docker/ - sudo touch /var/run/docker.sock + ls -lah /Users/runner/.docker/machine/ + sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & docker pull mcr.microsoft.com/mssql/server docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools From 64be270f604e07f05ab7e1b4420e6660a444ebb9 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 19:49:33 -0500 Subject: [PATCH 110/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 733cce9c..00660795 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,10 +60,12 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - ls -lah /Users/runner/.docker/machine/ + ls -lah /Users/runner/.docker/machine/machines/ + docker --help + docker info sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & - docker pull mcr.microsoft.com/mssql/server - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server + sodo docker pull mcr.microsoft.com/mssql/server + sodo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From f229341792c72ac708b42c749a072c471067a31a Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 20:02:27 -0500 Subject: [PATCH 111/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 00660795..ac98c225 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,12 +60,10 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - ls -lah /Users/runner/.docker/machine/machines/ - docker --help - docker info - sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & - sodo docker pull mcr.microsoft.com/mssql/server - sodo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server + docker version + sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & + sudo docker pull mcr.microsoft.com/mssql/server + sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 1290bacb93c3cbe5c6bc075757adaa3832ad2426 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 20:29:41 -0500 Subject: [PATCH 112/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index ac98c225..6cddea9e 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,13 +54,16 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install docker docker-machine + brew install docker docker-machine docker-compose brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) - name: Docker Install SQLServer run: | - docker version + sudo groupadd docker + sudo usermod -aG docker $(whoami) + docker-machine restart + ps aux | grep docker sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & sudo docker pull mcr.microsoft.com/mssql/server sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server From fc8142f558ecea1ea88f73bafc11d0fa7adefd21 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 20:45:34 -0500 Subject: [PATCH 113/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 6cddea9e..42df7258 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,10 +60,8 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - sudo groupadd docker - sudo usermod -aG docker $(whoami) docker-machine restart - ps aux | grep docker + env | grep DOCKER_HOST sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & sudo docker pull mcr.microsoft.com/mssql/server sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server From 1e67f50a104704b45a2b130d6e7e0104b19db37d Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 20:55:42 -0500 Subject: [PATCH 114/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 42df7258..c8c73b7b 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,7 +54,7 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install docker docker-machine docker-compose + brew install --cask docker brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) From 8371e0dbdedafc2f4c7d906aef7e911ac0bfb16a Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 21:08:26 -0500 Subject: [PATCH 115/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index c8c73b7b..3c219259 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,7 +54,7 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install --cask docker + brew install docker-machine --cask docker brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) From b5223e65f969b367d7e08ab0c1481e3f54402b3c Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 21:13:33 -0500 Subject: [PATCH 116/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 3c219259..fc6deee5 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,7 +54,8 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install docker-machine --cask docker + brew install --cask docker + brew install docker-machine brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) From 6812d85ec72b29c8c639bf58e3b13cc93b930881 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 21:27:33 -0500 Subject: [PATCH 117/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index fc6deee5..537558ca 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -61,10 +61,10 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - docker-machine restart + ln -s /Applications/Docker.app/Contents/Resources/bin /usr/local/bin/docker env | grep DOCKER_HOST + docker pull mcr.microsoft.com/mssql/server sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & - sudo docker pull mcr.microsoft.com/mssql/server sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | From 3afab86f332c8f39f58e02b098b184778cb6a173 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 21:39:40 -0500 Subject: [PATCH 118/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 537558ca..a0973ace 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,17 +54,15 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install --cask docker - brew install docker-machine + brew install docker-machine docker brew services start docker-machine docker-machine create --driver virtualbox default eval $(docker-machine env default) - name: Docker Install SQLServer run: | - ln -s /Applications/Docker.app/Contents/Resources/bin /usr/local/bin/docker env | grep DOCKER_HOST - docker pull mcr.microsoft.com/mssql/server sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & + sudo docker pull mcr.microsoft.com/mssql/server sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | From fb1b1e2b4677f9524fc27a8bc001c13067e4abf4 Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 21:49:17 -0500 Subject: [PATCH 119/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index a0973ace..c817b3e5 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -57,13 +57,13 @@ jobs: brew install docker-machine docker brew services start docker-machine docker-machine create --driver virtualbox default + docker-machine env default eval $(docker-machine env default) - name: Docker Install SQLServer run: | - env | grep DOCKER_HOST sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & - sudo docker pull mcr.microsoft.com/mssql/server - sudo docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server + docker pull mcr.microsoft.com/mssql/server + docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 90a5a9bb05d339338fef320268ae1504437c63ed Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 22:04:12 -0500 Subject: [PATCH 120/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index c817b3e5..7d78e1a6 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -57,11 +57,10 @@ jobs: brew install docker-machine docker brew services start docker-machine docker-machine create --driver virtualbox default - docker-machine env default eval $(docker-machine env default) - name: Docker Install SQLServer run: | - sudo nohup docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & + docker -H "${DOCKER_HOST}" docker pull mcr.microsoft.com/mssql/server docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools From c7e1063acc9c2b8c3682c48f19523cf84fe218fb Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 22:21:15 -0500 Subject: [PATCH 121/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 7d78e1a6..e9f756fe 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,7 +60,7 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - docker -H "${DOCKER_HOST}" + docker -H "${DOCKER_HOST}" unix:///var/run/docker.sock docker pull mcr.microsoft.com/mssql/server docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools From 5795653ccc5d3961cae4db6324a0950dc20b6b6a Mon Sep 17 00:00:00 2001 From: techno-express Date: Wed, 10 Feb 2021 22:30:28 -0500 Subject: [PATCH 122/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index e9f756fe..23890e0f 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,9 +60,8 @@ jobs: eval $(docker-machine env default) - name: Docker Install SQLServer run: | - docker -H "${DOCKER_HOST}" unix:///var/run/docker.sock - docker pull mcr.microsoft.com/mssql/server - docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server + docker -H "${DOCKER_HOST}" pull mcr.microsoft.com/mssql/server + docker -H "${DOCKER_HOST}" run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools run: | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" From 19b3cfa06c1046fc1cdd18f1db631460bac9599b Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 10:36:13 -0500 Subject: [PATCH 123/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 23890e0f..e0fa0688 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,12 +54,18 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install docker-machine docker - brew services start docker-machine - docker-machine create --driver virtualbox default + brew install docker-machine-driver-xhyve docker + sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve + sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve + while ! docker-machine create --driver xhyve default; do + docker-machine rm -f default + sleep 1; + done + docker-machine restart eval $(docker-machine env default) - name: Docker Install SQLServer run: | + echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts docker -H "${DOCKER_HOST}" pull mcr.microsoft.com/mssql/server docker -H "${DOCKER_HOST}" run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - name: Brew Install MSSQL Tools From 86c559500dc1512d9185362dc1b854015a5dc831 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 11:23:25 -0500 Subject: [PATCH 124/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index e0fa0688..7160616c 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -54,14 +54,12 @@ jobs: createdb --owner=ez_test ez_test - name: Install Docker, and Docker Machine run: | - brew install docker-machine-driver-xhyve docker + brew install --HEAD xhyve + brew install docker-machine-driver-xhyve sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve - while ! docker-machine create --driver xhyve default; do - docker-machine rm -f default - sleep 1; - done - docker-machine restart + brew services start docker-machine + docker-machine create --driver xhyve default eval $(docker-machine env default) - name: Docker Install SQLServer run: | From c62655e38708202c99226f44db6ab0b1360dbecb Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 11:40:32 -0500 Subject: [PATCH 125/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 7160616c..668e6d4b 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -55,7 +55,7 @@ jobs: - name: Install Docker, and Docker Machine run: | brew install --HEAD xhyve - brew install docker-machine-driver-xhyve + brew install docker-machine-driver-xhyve docker sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve brew services start docker-machine From fceaabf604df2ba0d565c6ac4a357385dec4dd75 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 11:47:06 -0500 Subject: [PATCH 126/148] Update and merge branch 'master' into v5 --- .github/workflows/ezsql-macos.yml | 26 +------- lib/ezFunctions.php | 100 +++++++++++++++++++++++++++++- lib/ezQueryInterface.php | 20 +++--- 3 files changed, 109 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 668e6d4b..1aa972af 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -26,7 +26,7 @@ jobs: uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, xdebug coverage: xdebug - name: Brew Install MySQL run: | @@ -52,30 +52,6 @@ jobs: createuser -s postgres psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - - name: Install Docker, and Docker Machine - run: | - brew install --HEAD xhyve - brew install docker-machine-driver-xhyve docker - sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve - sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve - brew services start docker-machine - docker-machine create --driver xhyve default - eval $(docker-machine env default) - - name: Docker Install SQLServer - run: | - echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts - docker -H "${DOCKER_HOST}" pull mcr.microsoft.com/mssql/server - docker -H "${DOCKER_HOST}" run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12!' -p 1433:1433 -d mcr.microsoft.com/mssql/server - - name: Brew Install MSSQL Tools - run: | - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release - brew update - HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install mssql-tools - - name: Setup SQLServer Database - run: | - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test" - sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test" - name: Install dependencies run: composer update - name: Test with phpunit diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 45ac335a..1a4b1241 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -310,6 +310,39 @@ function cleanInput($string) return ezQuery::clean($string); } + /** + * Returns an SQL string or result set, given the + * - table, column fields, conditions or conditional array. + * + * In the following format: + * ```js + * select( + * table, + * columns, + * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ), + * union(table, columnFields, conditions), // Returns an select SQL string with `UNION` + * unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL` + *); + * ``` + * @param $table, - database table to access + * @param $columnFields, - table columns, string or array + * @param mixed ...$conditions - of the following parameters: + * + * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) + * @param $whereKey, - where clause ( comparison(x, y, and) ) + * @param $groupBy, - grouping over clause the results + * @param $having, - having clause ( comparison(x, y, and) ) + * @param $orderby, - ordering by clause for the query + * @param $limit, - limit clause the number of records + * @param $union/$unionAll - union clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed result set - see docs for more details, or false for error + */ function select($table = '', $columns = '*', ...$args) { $ezQuery = \getInstance(); @@ -318,6 +351,15 @@ function select($table = '', $columns = '*', ...$args) : false; } + /** + * Does an select into statement by calling selecting method + * @param $newTable, - new database table to be created + * @param $fromColumns - the columns from old database table + * @param $oldTable - old database table + * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * + * @return mixed bool/result - false for error + */ function select_into($table, $columns = '*', $old = null, ...$args) { $ezQuery = \getInstance(); @@ -342,14 +384,68 @@ function create_select($table, $from, $old = null, ...$args) : false; } - function where(...$args) + /** + * Returns an `WHERE` **sql clause** string. + * + * format: + * `where( comparison(x, y, and) )` + * + * example: + * `where( eq(key, value ), like('key', '_%?');` + * + * @param array $whereConditions - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/string - WHERE sql statement, or false on error + */ + function where(...$whereConditions) { $ezQuery = \getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->where(...$args) + ? $ezQuery->where(...$whereConditions) : false; } + /** + * Adds WHERE grouping to the conditions + * + * format: + * `grouping( comparison(x, y, and) )` + * + * example: + * `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );` + * + * @param array $whereConditions - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression again + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + *``` + * @return array modified conditions + */ function grouping(...$args) { $ezQuery = \getInstance(); diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 5007d1d2..6ce44b58 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -304,7 +304,7 @@ public function limit($numberOf, $offset = null); * `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );` * * @param array $whereConditions - In the following format: - * + *```js * eq('key/Field/Column', $value, _AND), // combine next expression * neq('key/Field/Column', $value, _OR), // will combine next expression again * ne('key/Field/Column', $value), // the default is _AND so will combine next expression @@ -316,7 +316,7 @@ public function limit($numberOf, $offset = null); * isNotNull('key/Field/Column') * like('key/Field/Column', '_%') * notLike('key/Field/Column', '_%') - * + *``` * @return array modified conditions */ public function grouping(...$whereConditions); @@ -331,9 +331,9 @@ public function grouping(...$whereConditions); * `where( eq(key, value ), like('key', '_%?');` * * @param array $whereConditions - In the following format: - * + *```js * eq('key/Field/Column', $value, _AND), // combine next expression - * neq('key/Field/Column', $value, _OR), // will combine next expression again + * neq('key/Field/Column', $value, _OR), // will combine next expression if * ne('key/Field/Column', $value), // the default is _AND so will combine next expression * lt('key/Field/Column', $value) * lte('key/Field/Column', $value) @@ -347,22 +347,22 @@ public function grouping(...$whereConditions); * notIn('key/Field/Column', $values) * between('key/Field/Column', $value, $value2) * notBetween('key/Field/Column', $value, $value2) - * + *``` * @return mixed bool/string - WHERE SQL statement, or false on error */ public function where(...$whereConditions); + /** * Returns an SQL string or result set, given the * - table, column fields, conditions or conditional array. * * In the following format: - * ``` - * selecting( + * ```js + * select( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -374,7 +374,7 @@ public function where(...$whereConditions); * ``` * @param $table, - database table to access * @param $columnFields, - table columns, string or array - * @param mixed $conditions - of the following parameters: + * @param mixed ...$conditions - of the following parameters: * * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) * @param $whereKey, - where clause ( comparison(x, y, and) ) From 8a62090737f3d3d287d66cac0e06a693c149ec2a Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 12:06:57 -0500 Subject: [PATCH 127/148] update --- .github/workflows/ezsql-macos.yml | 4 ++-- tests/mysqli/mysqliTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 1aa972af..2e9b77bd 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [macos-latest] - php-versions: ['7.3'] + php-versions: ['7.2', '7.3', '7.4'] steps: - name: Checkout @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: composer update - name: Test with phpunit - run: vendor/bin/phpunit --coverage-clover=coverage.xml + run: ./vendor/bin/phpunit - name: Submit code coverage uses: codecov/codecov-action@v1 with: diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 40d2f367..87618173 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -90,7 +90,7 @@ public function testSelect() $this->assertTrue($result); $this->errors = array(); - //set_error_handler(array($this, 'errorHandler')); + set_error_handler(array($this, 'errorHandler')); $this->assertTrue($this->object->select('')); $this->object->disconnect(); $this->assertFalse($this->object->select('notest')); From 1d8c85b1e01982d11e4e7626e2e9d9ff22f7da4e Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 12:37:26 -0500 Subject: [PATCH 128/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 2e9b77bd..e4f5edde 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [macos-latest] - php-versions: ['7.2', '7.3', '7.4'] + php-versions: ['7.1', '8.0'] steps: - name: Checkout @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: composer update - name: Test with phpunit - run: ./vendor/bin/phpunit + run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - name: Submit code coverage uses: codecov/codecov-action@v1 with: From 9b77f5e1185159223a8b5c06b705a1f02471b5e4 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 12:44:42 -0500 Subject: [PATCH 129/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index e4f5edde..04addca9 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -26,8 +26,7 @@ jobs: uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, xdebug - coverage: xdebug + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite - name: Brew Install MySQL run: | brew install mysql@5.7 From 97e801192c64e4411981bf952b07bcfbbc2fb68a Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 12:57:16 -0500 Subject: [PATCH 130/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 04addca9..0aca1447 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -26,7 +26,8 @@ jobs: uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, xdebug + coverage: xdebug - name: Brew Install MySQL run: | brew install mysql@5.7 From 2f3c668e45e73b97d38bfa7c269f61f24a9e67da Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 13:08:05 -0500 Subject: [PATCH 131/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 0aca1447..1f50ba26 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -12,11 +12,11 @@ on: jobs: windows: name: macOS (PHP ${{ matrix.php-versions }} CI) - runs-on: macos-latest + runs-on: macos-11.0 strategy: fail-fast: false matrix: - operating-system: [macos-latest] + operating-system: [macos-11.0] php-versions: ['7.1', '8.0'] steps: From 51435cf297f674877752b4fd5f156a0d2c163d18 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 13:13:08 -0500 Subject: [PATCH 132/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 1f50ba26..89015018 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -12,12 +12,12 @@ on: jobs: windows: name: macOS (PHP ${{ matrix.php-versions }} CI) - runs-on: macos-11.0 + runs-on: macos-latest strategy: fail-fast: false matrix: - operating-system: [macos-11.0] - php-versions: ['7.1', '8.0'] + operating-system: [macos-latest] + php-versions: ['7.3'] steps: - name: Checkout @@ -26,7 +26,7 @@ jobs: uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, xdebug + extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, xdebug coverage: xdebug - name: Brew Install MySQL run: | @@ -53,7 +53,9 @@ jobs: psql -U postgres --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du" createdb --owner=ez_test ez_test - name: Install dependencies - run: composer update + run: | + composer self-update + composer update - name: Test with phpunit run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - name: Submit code coverage From 5b3966ad2ab2d5a6ddda6d39c48b5a057902b070 Mon Sep 17 00:00:00 2001 From: techno-express Date: Thu, 11 Feb 2021 19:06:12 -0500 Subject: [PATCH 133/148] Update ezFunctionsTest.php --- tests/ezFunctionsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index e080bb21..197acba9 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -149,7 +149,6 @@ public function testNotBetween() public function testSetInstance() { $this->assertFalse(\setInstance()); - $this->assertFalse(\setInstance($this)); } public function testSelect() From 227199754ae92f51c494586b4e9344e540bc5358 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 12 Feb 2021 12:26:37 -0500 Subject: [PATCH 134/148] Update ezsql-macos.yml --- .github/workflows/ezsql-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 89015018..03673276 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -13,6 +13,7 @@ jobs: windows: name: macOS (PHP ${{ matrix.php-versions }} CI) runs-on: macos-latest + continue-on-error: true strategy: fail-fast: false matrix: From a56baf4374999abfd6dbd02a01c4942b2cf75bd4 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 12 Feb 2021 15:50:56 -0500 Subject: [PATCH 135/148] namespace `ezFunctions.php` file global functions, update database files and tests - this is a breaking change requiring major version change --- README.md | 21 +++++++-- lib/ConfigAbstract.php | 28 ++++++++++++ lib/ConfigInterface.php | 2 + lib/Constants.php | 2 +- lib/Database.php | 5 ++- lib/Database/ez_mysqli.php | 3 +- lib/Database/ez_pdo.php | 3 +- lib/Database/ez_pgsql.php | 3 +- lib/Database/ez_sqlite3.php | 3 +- lib/Database/ez_sqlsrv.php | 3 +- lib/DatabaseInterface.php | 4 +- lib/ezFunctions.php | 68 +++++++++++++++-------------- lib/ezQuery.php | 3 +- lib/ezResultset.php | 2 +- lib/ezSchema.php | 8 +++- lib/ezsqlModel.php | 3 +- tests/DatabaseTest.php | 4 +- tests/ezFunctionsTest.php | 44 ++++++++++++++++++- tests/ezQueryTest.php | 7 +++ tests/ezSchemaTest.php | 12 +++++ tests/mysqli/ezResultsetTest.php | 7 ++- tests/mysqli/mysqliTest.php | 46 ++++++++++++++++--- tests/pdo/pdo_mysqlTest.php | 17 +++++++- tests/pdo/pdo_pgsqlTest.php | 12 ++++- tests/pdo/pdo_sqliteTest.php | 12 ++++- tests/pdo/pdo_sqlsrvTest.php | 12 ++++- tests/postgresql/postgresqlTest.php | 10 ++++- tests/sqlite/sqlite3Test.php | 10 ++++- tests/sqlsrv/sqlsrvTest.php | 10 ++++- 29 files changed, 290 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 8a1a4782..e591b2c1 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,29 @@ [![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg?branch=v5)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows) [![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg?branch=v5)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux) -[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL) +[![macOS](https://github.com/ezSQL/ezsql/workflows/macOS/badge.svg?branch=v5)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AmacOS) +[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/v5/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aad1f6aaaaa14f60933e75615da900b8)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com&utm_medium=referral&utm_content=ezSQL/ezsql&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability) -[![Total Downloads](https://poser.pugx.org/jv2222/ezsql/downloads)](https://packagist.org/packages/jv2222/ezsql) +[![Total Downloads](https://poser.pugx.org/ezsql/ezsql/downloads)](https://packagist.org/packages/ezsql/ezsql) ***A class to make it very easy to deal with database connections.*** -This is [__version 4__](https://github.com/ezSQL/ezsql/tree/v4) that has many modern programming practices in which will break users of version 3. +This is a [WIP] of [__version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**, mainly by the use of `namespace` in the `global` functions **ezFunctions.php** file. + +Usage of the **global** functions will require the user to begin a `.php` file something like: + +```php +use function ezsql\functions\where; +// Or +use function ezsql\functions\{ + getInstance, + select, + insert, +}; +``` + +[__version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. [__Version 3__](https://github.com/ezSQL/ezsql/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features. diff --git a/lib/ConfigAbstract.php b/lib/ConfigAbstract.php index ef660a40..9e365758 100644 --- a/lib/ConfigAbstract.php +++ b/lib/ConfigAbstract.php @@ -25,6 +25,34 @@ /** * @method set/get{property} - a property that needs to be accessed + * + * @method void setDriver($args); + * @method void setDsn($args); + * @method void setUser($args); + * @method void setPassword($args); + * @method void setName($args); + * @method void setHost($args); + * @method void setPort($args); + * @method void setCharset($args); + * @method void setOptions($args); + * @method void setIsFile($args); + * @method void setToMssql($args); + * @method void setToMysql($args); + * @method void setPath($args); + * + * @method string getDriver(); + * @method string getDsn(); + * @method string getUser(); + * @method string getPassword() + * @method string getName(); + * @method string getHost(); + * @method string getPort(); + * @method string getCharset(); + * @method string getOptions(); + * @method string getToMysql(); + * @method bool getIsFile(); + * @method bool getToMssql();getToMssql + * @method string getPath(); */ abstract class ConfigAbstract { diff --git a/lib/ConfigInterface.php b/lib/ConfigInterface.php index 17081fc9..681b54c7 100644 --- a/lib/ConfigInterface.php +++ b/lib/ConfigInterface.php @@ -13,6 +13,7 @@ * @method void setCharset($args); * @method void setOptions($args); * @method void setIsFile($args); + * @method void setToMssql($args); * @method void setToMysql($args); * @method void setPath($args); * @@ -27,6 +28,7 @@ * @method string getOptions(); * @method bool getIsFile(); * @method bool getToMysql(); + * @method bool getToMssql(); * @method string getPath(); */ interface ConfigInterface diff --git a/lib/Constants.php b/lib/Constants.php index 384a85e4..6c0fbce0 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -5,7 +5,7 @@ /** * ezsqlModel Constants */ - \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '4.0.12'); + \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.0.0'); \defined('OBJECT') or \define('OBJECT', 'OBJECT'); \defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A'); \defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N'); diff --git a/lib/Database.php b/lib/Database.php index 914d0687..910dbf90 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -5,6 +5,7 @@ namespace ezsql; use ezsql\DInjector; +use function ezsql\functions\setInstance; class Database { @@ -38,7 +39,7 @@ public function __wakeup() public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) { if (isset(self::$instances[$vendor]) && empty($setting) && empty($tag)) - return \setInstance(self::$instances[$vendor]) ? self::$instances[$vendor] : false; + return setInstance(self::$instances[$vendor]) ? self::$instances[$vendor] : false; if (empty($vendor) || empty($setting)) { throw new \Exception(\MISSING_CONFIGURATION); @@ -58,7 +59,7 @@ public static function initialize(?string $vendor = null, ?array $setting = null } } - \setInstance($GLOBALS['ez' . $key]); + setInstance($GLOBALS['ez' . $key]); return $GLOBALS['ez' . $key]; } } diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 2ec89afb..de347ce2 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -8,6 +8,7 @@ use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; +use function ezsql\functions\setInstance; class ez_mysqli extends ezsqlModel implements DatabaseInterface { @@ -45,7 +46,7 @@ public function __construct(ConfigInterface $settings = null) if (empty($GLOBALS['ez' . \MYSQLI])) $GLOBALS['ez' . \MYSQLI] = $this; - \setInstance($this); + setInstance($this); } // __construct public function settings() diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index f3790581..593de53a 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -9,6 +9,7 @@ use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; +use function ezsql\functions\setInstance; class ez_pdo extends ezsqlModel implements DatabaseInterface { @@ -49,7 +50,7 @@ public function __construct(ConfigInterface $settings = null) if (empty($GLOBALS['ez' . \Pdo])) $GLOBALS['ez' . \Pdo] = $this; - \setInstance($this); + setInstance($this); } // __construct public function settings() diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 3d5eed8c..daf90e4b 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -8,6 +8,7 @@ use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; +use function ezsql\functions\setInstance; class ez_pgsql extends ezsqlModel implements DatabaseInterface { @@ -45,7 +46,7 @@ public function __construct(ConfigInterface $settings = null) if (empty($GLOBALS['ez' . \PGSQL])) $GLOBALS['ez' . \PGSQL] = $this; - \setInstance($this); + setInstance($this); } // __construct public function settings() diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index b7dead0e..462b4cd9 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -8,6 +8,7 @@ use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; +use function ezsql\functions\setInstance; class ez_sqlite3 extends ezsqlModel implements DatabaseInterface { @@ -52,7 +53,7 @@ public function __construct(ConfigInterface $settings = null) if (!isset($GLOBALS['ez' . \SQLITE3])) $GLOBALS['ez' . \SQLITE3] = $this; - \setInstance($this); + setInstance($this); } public function settings() diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index 154f260f..693fd514 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -8,6 +8,7 @@ use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; +use function ezsql\functions\setInstance; class ez_sqlsrv extends ezsqlModel implements DatabaseInterface { @@ -54,7 +55,7 @@ public function __construct(ConfigInterface $settings = null) if (empty($GLOBALS['ez' . \SQLSRV])) $GLOBALS['ez' . \SQLSRV] = $this; - \setInstance($this); + setInstance($this); } public function settings() diff --git a/lib/DatabaseInterface.php b/lib/DatabaseInterface.php index 8e9040d8..ca5ae9d5 100644 --- a/lib/DatabaseInterface.php +++ b/lib/DatabaseInterface.php @@ -18,6 +18,7 @@ interface DatabaseInterface * - getOptions(); * - getIsFile(); * - getToMssql(); + * - getToMysql(); * - getPath(); *--- * - setDriver($args); @@ -31,9 +32,10 @@ interface DatabaseInterface * - setOptions($args); * - setIsFile($args); * - setToMssql($args); + * - setToMysql($args); * - setPath($args); * - * @return string|array|bool|void + * @return string|array|bool|object */ public function settings(); diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index e3d53cff..39121e42 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -1,5 +1,9 @@ selecting($table, $columns, ...$args) : false; @@ -569,7 +573,7 @@ function select($table = '', $columns = '*', ...$args) */ function select_into($table, $columns = '*', $old = null, ...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->select_into($table, $columns, $old, ...$args) : false; @@ -585,7 +589,7 @@ function select_into($table, $columns = '*', $old = null, ...$args) */ function insert_select($totable = '', $columns = '*', $fromTable = null, $from = '*', ...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->insert_select($totable, $columns, $fromTable, $from, ...$args) : false; @@ -603,7 +607,7 @@ function insert_select($totable = '', $columns = '*', $fromTable = null, $from = */ function create_select($table, $from, $old = null, ...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->create_select($table, $from, $old, ...$args) : false; @@ -640,7 +644,7 @@ function create_select($table, $from, $old = null, ...$args) */ function where(...$whereConditions) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->where(...$whereConditions) : false; @@ -673,7 +677,7 @@ function where(...$whereConditions) */ function grouping(...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->grouping(...$args) : false; @@ -695,7 +699,7 @@ function grouping(...$args) */ function groupBy($groupBy) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->groupBy($groupBy) : false; @@ -726,7 +730,7 @@ function groupBy($groupBy) */ function having(...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->having(...$args) : false; @@ -763,7 +767,7 @@ function innerJoin( $tableAs = null, $condition = \EQ ) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->innerJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition) : false; @@ -802,7 +806,7 @@ function leftJoin( $tableAs = null, $condition = \EQ ) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->leftJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition) : false; @@ -841,7 +845,7 @@ function rightJoin( $tableAs = null, $condition = \EQ ) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->rightJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition) : false; @@ -879,7 +883,7 @@ function fullJoin( $tableAs = null, $condition = \EQ ) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->fullJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition) : false; @@ -911,7 +915,7 @@ function fullJoin( */ function union($table = '', $columnFields = '*', ...$conditions) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->union($table, $columnFields, ...$conditions) : false; @@ -943,7 +947,7 @@ function union($table = '', $columnFields = '*', ...$conditions) */ function unionAll($table = '', $columnFields = '*', ...$conditions) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->unionAll($table, $columnFields, ...$conditions) : false; @@ -958,7 +962,7 @@ function unionAll($table = '', $columnFields = '*', ...$conditions) */ function orderBy($orderBy, $order) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->orderBy($orderBy, $order) : false; @@ -975,7 +979,7 @@ function orderBy($orderBy, $order) */ function limit($numberOf, $offset = null) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->limit($numberOf, $offset) : false; @@ -989,7 +993,7 @@ function limit($numberOf, $offset = null) */ function insert($table = '', $keyValue = null) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->insert($table, $keyValue) : false; @@ -1005,7 +1009,7 @@ function insert($table = '', $keyValue = null) */ function update($table = '', $keyValue = null, ...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->update($table, $keyValue, ...$args) : false; @@ -1017,7 +1021,7 @@ function update($table = '', $keyValue = null, ...$args) */ function deleting($table = '', ...$args) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->delete($table, ...$args) : false; @@ -1031,7 +1035,7 @@ function deleting($table = '', ...$args) */ function replace($table = '', $keyValue = null) { - $ezQuery = \getInstance(); + $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) ? $ezQuery->replace($table, $keyValue) : false; diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 88a76f5d..02c85f17 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -4,6 +4,7 @@ use ezsql\ezSchema; use ezsql\ezQueryInterface; +use function ezsql\functions\column; class ezQuery implements ezQueryInterface { @@ -868,7 +869,7 @@ private function create_schema(array ...$columnDataOptions) $column = \array_shift($datatype); $type = \array_shift($datatype); if (!empty($column) && !empty($type)) - $columnData .= \column($column, $type, ...$datatype); + $columnData .= column($column, $type, ...$datatype); } $schemaColumns = !empty($columnData) ? \rtrim($columnData, ', ') : null; diff --git a/lib/ezResultset.php b/lib/ezResultset.php index 054b67cb..6e17783a 100644 --- a/lib/ezResultset.php +++ b/lib/ezResultset.php @@ -181,7 +181,7 @@ public function fetch_row() /** * Returns n object with properties that correspond to the fetched row and moves * the internal data pointer ahead. Behaves like mysql_fetch_object. - * @return array + * @return object */ public function fetch_object() { diff --git a/lib/ezSchema.php b/lib/ezSchema.php index 8c0c75a0..2617ab04 100644 --- a/lib/ezSchema.php +++ b/lib/ezSchema.php @@ -3,6 +3,10 @@ namespace ezsql; use ezsql\DatabaseInterface; +use function ezsql\functions\{ + getInstance, + to_string +}; class ezSchema { @@ -156,7 +160,7 @@ public function __call($type, $args) public static function vendor() { $type = null; - $instance = \getInstance(); + $instance = getInstance(); if ($instance instanceof DatabaseInterface) { $type = $instance->settings()->getDriver(); if ($type == \Pdo) { @@ -205,7 +209,7 @@ public static function column(string $column = null, string $type = null, ...$ar } $keyType = ($column != \INDEX) ? \array_shift($args) . ' ' : ' '; - $keys = $keyType . '(' . \to_string($args) . '), '; + $keys = $keyType . '(' . to_string($args) . '), '; $columnData .= $column . ' ' . $type . ' ' . $keys; } elseif (($column == \ADD) || ($column == \DROP) || ($column == \CHANGER)) { if ($column != \DROP) { diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 6de9efc3..679d3f48 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -4,6 +4,7 @@ use ezsql\ezQuery; use ezsql\ezsqlModelInterface; +use function ezsql\functions\getVendor; /** * Core class containing common functions to manipulate query result @@ -703,7 +704,7 @@ public function secureSetup( string $path = '.' . \_DS ) { if (!\file_exists($path . $cert) || !\file_exists($path . $key)) { - $vendor = \getVendor(); + $vendor = getVendor(); if (($vendor != \SQLITE) || ($vendor != \MSSQL)) $path = ezQuery::createCertificate(); } elseif ($path == '.' . \_DS) { diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index dcdd9b29..b5deca6d 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -11,6 +11,8 @@ use ezsql\Database\ez_sqlsrv; use ezsql\Tests\EZTestCase; +use function ezsql\functions\tagInstance; + class DatabaseTest extends EZTestCase { public function testInitialize() @@ -28,7 +30,7 @@ public function testInitialize() $this->assertTrue($mysqli->getShow_Errors()); $benchmark = Database::benchmark(); $this->assertNotNull($benchmark['start']); - $this->assertSame($mysqli, \tagInstance(MYSQLI)); + $this->assertSame($mysqli, tagInstance(MYSQLI)); } public function testInitialize_Pgsql() diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index 197acba9..e0cb0885 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -4,11 +4,51 @@ use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + setInstance, + getInstance, + clearInstance, + getVendor, + column, + primary, + foreign, + unique, + index, + addColumn, + dropColumn, + eq, + neq, + ne, + lt, + lte, + gt, + gte, + isNotNull, + like, + in, + notLike, + notIn, + between, + notBetween, + select, + select_into, + insert_select, + create_select, + where, + groupBy, + having, + orderBy, + insert, + update, + deleting, + replace +}; + class ezFunctionsTest extends EZTestCase { protected function setUp(): void { - \clearInstance(); + clearInstance(); } public function testGetInstance() @@ -148,7 +188,7 @@ public function testNotBetween() public function testSetInstance() { - $this->assertFalse(\setInstance()); + $this->assertFalse(setInstance()); } public function testSelect() diff --git a/tests/ezQueryTest.php b/tests/ezQueryTest.php index e77ec67d..3aacdeab 100644 --- a/tests/ezQueryTest.php +++ b/tests/ezQueryTest.php @@ -5,6 +5,13 @@ use ezsql\ezQuery; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + eq, + neq, + like, + in, +}; + class ezQueryTest extends EZTestCase { protected $object; diff --git a/tests/ezSchemaTest.php b/tests/ezSchemaTest.php index d7757f25..8f05ac73 100644 --- a/tests/ezSchemaTest.php +++ b/tests/ezSchemaTest.php @@ -4,6 +4,18 @@ use ezsql\ezSchema; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + pdoInstance, + pgsqlInstance, + mysqlInstance, + mssqlInstance, + sqliteInstance, + clearInstance, + getVendor, + column, + primary, + index, +}; class ezSchemaTest extends EZTestCase { diff --git a/tests/mysqli/ezResultsetTest.php b/tests/mysqli/ezResultsetTest.php index 5dee81e4..66191e3a 100644 --- a/tests/mysqli/ezResultsetTest.php +++ b/tests/mysqli/ezResultsetTest.php @@ -5,6 +5,11 @@ use ezsql\ezResultset; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + mysqlInstance, + column, +}; + class ezResultsetTest extends EZTestCase { /** @@ -14,7 +19,7 @@ class ezResultsetTest extends EZTestCase /** * database connection - * @var resource + * @var object */ protected $database = null; diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 87618173..6c7ae924 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -7,6 +7,38 @@ use ezsql\Database\ez_mysqli; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + mysqlInstance, + column, + primary, + eq, + neq, + ne, + lt, + lte, + gt, + gte, + isNotNull, + like, + in, + notLike, + notIn, + between, + notBetween, + select, + select_into, + insert_select, + create_select, + where, + groupBy, + having, + orderBy, + insert, + update, + deleting, + replace +}; + class mysqliTest extends EZTestCase { @@ -208,15 +240,15 @@ public function testGetInsertId() public function testCreate() { - $object = \mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); + $object = mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); $this->assertEquals($this->object, $object); $object->prepareOff(); $this->assertEquals( $object->create( 'create_test', - \column('id', INTR, 11, \AUTO), - \column('create_key', VARCHAR, 50), - \primary('id_pk', 'id') + column('id', INTR, 11, \AUTO), + column('create_key', VARCHAR, 50), + primary('id_pk', 'id') ), 0 ); @@ -239,9 +271,9 @@ public function testInsert() $object->connect(); $object->create( 'unit_test', - \column('id', INTR, 11, \AUTO), - \column('test_key', VARCHAR, 50), - \primary('id_pk', 'id') + column('id', INTR, 11, \AUTO), + column('test_key', VARCHAR, 50), + primary('id_pk', 'id') ); $this->assertEquals(1, $this->object->insert('unit_test', array('test_key' => 'test 2'))); } diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index a6c1c7d5..d7234927 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -2,11 +2,24 @@ namespace ezsql\Tests\pdo; -use ezsql\Database; use ezsql\Config; use ezsql\Database\ez_pdo; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + pdoInstance, + leftJoin, + column, + primary, + insert, + update, + select, + grouping, + like, + where, + eq, +}; + class pdo_mysqlTest extends EZTestCase { @@ -32,7 +45,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('pdo', ['mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); + $this->object = pdoInstance(['mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); $this->object->prepareOn(); } // setUp diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 70780444..202246e1 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -2,9 +2,17 @@ namespace ezsql\Tests\pdo; -use ezsql\Database; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + pdoInstance, + leftJoin, + grouping, + like, + where, + eq, +}; + class pdo_pgsqlTest extends EZTestCase { /** @@ -34,7 +42,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('pdo', ['pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); + $this->object = pdoInstance(['pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); $this->object->prepareOn(); } // setUp diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index d9644c73..acdd1bde 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -2,9 +2,17 @@ namespace ezsql\Tests\pdo; -use ezsql\Database; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + pdoInstance, + leftJoin, + grouping, + like, + where, + eq, +}; + class pdo_sqliteTest extends EZTestCase { /** @@ -33,7 +41,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('pdo', ['sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true]); + $this->object = pdoInstance(['sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true]); $this->object->prepareOn(); } // setUp diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index 58619195..783845ef 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -2,9 +2,17 @@ namespace ezsql\Tests\pdo; -use ezsql\Database; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + grouping, + where, + eq, + like, + leftJoin, + pdoInstance, +}; + class pdo_sqlsrvTest extends EZTestCase { /** @@ -24,7 +32,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('pdo', ['sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); + $this->object = pdoInstance(['sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); $this->object->prepareOn(); } // setUp diff --git a/tests/postgresql/postgresqlTest.php b/tests/postgresql/postgresqlTest.php index 13f74560..fb9910ea 100644 --- a/tests/postgresql/postgresqlTest.php +++ b/tests/postgresql/postgresqlTest.php @@ -2,11 +2,17 @@ namespace ezsql\Tests\postgresql; -use ezsql\Database; use ezsql\Config; use ezsql\Database\ez_pgsql; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + column, + primary, + eq, + pgsqlInstance, +}; + class postgresqlTest extends EZTestCase { /** @@ -31,7 +37,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('pgsql', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]); + $this->object = pgsqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]); $this->object->prepareOn(); } diff --git a/tests/sqlite/sqlite3Test.php b/tests/sqlite/sqlite3Test.php index c7af48bc..2dcd2f4d 100644 --- a/tests/sqlite/sqlite3Test.php +++ b/tests/sqlite/sqlite3Test.php @@ -3,11 +3,17 @@ namespace ezsql\Tests\sqlite; use Exception; -use ezsql\Database; use ezsql\Config; use ezsql\Database\ez_sqlite3; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + column, + primary, + eq, + sqliteInstance, +}; + /** * Generated by PHPUnit_SkeletonGenerator on 2018-03-08 at 02:54:12. */ @@ -36,7 +42,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('sqlite3', [self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]); + $this->object = sqliteInstance([self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]); $this->object->prepareOn(); } diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index 04df061f..cf6003cc 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -2,11 +2,17 @@ namespace ezsql\Tests\sqlsrv; -use ezsql\Database; use ezsql\Config; use ezsql\Database\ez_sqlsrv; use ezsql\Tests\EZTestCase; +use function ezsql\functions\{ + column, + primary, + eq, + mssqlInstance, +}; + class sqlsrvTest extends EZTestCase { @@ -27,7 +33,7 @@ protected function setUp(): void ); } - $this->object = Database::initialize('sqlsrv', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); + $this->object = mssqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); $this->object->prepareOn(); } From 3fd6fec8a0857002caabd76bd686a804a08d2b93 Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 12 Feb 2021 19:25:40 -0500 Subject: [PATCH 136/148] update/correction --- .github/workflows/ezsql-macos.yml | 1 + tests/ezFunctionsTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ezsql-macos.yml b/.github/workflows/ezsql-macos.yml index 03673276..57d364b6 100644 --- a/.github/workflows/ezsql-macos.yml +++ b/.github/workflows/ezsql-macos.yml @@ -60,6 +60,7 @@ jobs: - name: Test with phpunit run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - name: Submit code coverage + if: ${{ success() }} || ${{ failure() }} uses: codecov/codecov-action@v1 with: file: ./coverage.xml # optional diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index e0cb0885..d853945c 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -23,6 +23,7 @@ lte, gt, gte, + isNull, isNotNull, like, in, From 8ee4c740aedc125bb2aeef4a4043a7e8c619adf9 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 13:05:12 -0500 Subject: [PATCH 137/148] More breaking changes, and corrections - class properties that was accessible with `get/set`, now PSR 1 camelCase - update class libraries and tests to match - renamed `select` of `ez_mysqli` to `dbSelect` - update tests to match `dbSelect` - renamed class method `selecting` to `select` - update tests to match `select` --- lib/Database.php | 6 +- lib/Database/ez_mysqli.php | 46 ++-- lib/Database/ez_pdo.php | 49 ++-- lib/Database/ez_pgsql.php | 22 +- lib/Database/ez_sqlite3.php | 28 +-- lib/Database/ez_sqlsrv.php | 18 +- lib/ezFunctions.php | 47 ++-- lib/ezQuery.php | 25 +- lib/ezQueryInterface.php | 2 +- lib/ezResultset.php | 2 +- lib/ezSchema.php | 15 +- lib/ezsqlModel.php | 366 ++++++++++++++-------------- lib/ezsqlModelInterface.php | 2 +- tests/DatabaseTest.php | 8 +- tests/ezQueryTest.php | 6 +- tests/ezsqlModelTest.php | 20 +- tests/mysqli/ezResultsetTest.php | 2 +- tests/mysqli/mysqliTest.php | 51 ++-- tests/pdo/pdo_mysqlTest.php | 20 +- tests/pdo/pdo_pgsqlTest.php | 16 +- tests/pdo/pdo_sqliteTest.php | 16 +- tests/pdo/pdo_sqlsrvTest.php | 16 +- tests/postgresql/postgresqlTest.php | 16 +- tests/sqlite/sqlite3Test.php | 16 +- tests/sqlsrv/sqlsrvTest.php | 16 +- 25 files changed, 418 insertions(+), 413 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 910dbf90..b27cc78c 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -31,9 +31,9 @@ public function __wakeup() /** * Initialize and connect a vendor database. * - * @param mixed $vendor - SQL driver - * @param mixed $setting - SQL connection parameters - * @param mixed $tag - Store the instance for later use + * @param string $vendor SQL driver + * @param array $setting SQL connection parameters + * @param string $tag Store the instance for later use * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index de347ce2..d8923bd0 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -14,7 +14,6 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface { private $return_val = 0; private $is_insert = false; - private $shortcutUsed = false; private $isTransactional = false; /** @@ -34,6 +33,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface * @var ConfigInterface */ private $database; + protected $shortcutUsed = false; public function __construct(ConfigInterface $settings = null) { @@ -82,7 +82,7 @@ public function quick_connect( $charset = empty($charset) ? $this->database->getCharset() : $charset; if (!$this->connect($user, $password, $host, (int) $port, $charset)); - else if (!$this->select($name, $charset)); + else if (!$this->dbSelect($name, $charset)); return $this->_connected; } // quick_connect @@ -125,13 +125,13 @@ public function connect( } // connect /** - * Try to select a mySQL database + * Try to select the default database for mySQL * * @param string $name The name of the database * @param string $charset Encoding of the database * @return boolean */ - public function select($name = '', $charset = '') + public function dbSelect($name = '', $charset = '') { $name = empty($name) ? $this->database->getName() : $name; try { @@ -213,9 +213,9 @@ private function fetch_prepared_result(&$stmt, $query) if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { $this->_affectedRows = \mysqli_stmt_affected_rows($stmt); - // Take note of the insert_id + // Take note of the insert id if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = $stmt->insert_id; + $this->insertId = $stmt->insert_id; } } else { $this->_affectedRows = $stmt->num_rows; @@ -226,7 +226,7 @@ private function fetch_prepared_result(&$stmt, $query) while ($field = $meta->fetch_field()) { $col_info[$field->name] = ""; $variables[$field->name] = &$col_info[$field->name]; - $this->col_info[$x] = $field; + $this->colInfo[$x] = $field; $x++; } @@ -241,7 +241,7 @@ private function fetch_prepared_result(&$stmt, $query) foreach ($variables as $key => $value) { $resultObject->$key = $value; } - $this->last_result[$i] = $resultObject; + $this->lastResult[$i] = $resultObject; $i++; } } @@ -252,7 +252,7 @@ private function fetch_prepared_result(&$stmt, $query) $this->register_error($str); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return false; } @@ -263,7 +263,7 @@ private function fetch_prepared_result(&$stmt, $query) $this->store_cache($query, $is_insert); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $return_val; } @@ -283,7 +283,7 @@ public function query_prepared(string $query, array $param = null) $stmt = $this->dbh->prepare($query); if (!$stmt instanceof \mysqli_stmt) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->lastError); return false; } @@ -339,7 +339,7 @@ private function processQueryResult(string $query, $result = null) $this->register_error($str); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return false; } @@ -351,7 +351,7 @@ private function processQueryResult(string $query, $result = null) // Take note of the insert_id if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = \mysqli_insert_id($this->dbh); + $this->insertId = \mysqli_insert_id($this->dbh); } // Return number of rows affected @@ -363,7 +363,7 @@ private function processQueryResult(string $query, $result = null) // Take note of column info $i = 0; while ($i < \mysqli_num_fields($this->result)) { - $this->col_info[$i] = \mysqli_fetch_field($this->result); + $this->colInfo[$i] = \mysqli_fetch_field($this->result); $i++; } @@ -371,17 +371,17 @@ private function processQueryResult(string $query, $result = null) $num_rows = 0; while ($row = \mysqli_fetch_object($this->result)) { // Store results as an objects within main array - $this->last_result[$num_rows] = $row; + $this->lastResult[$num_rows] = $row; $num_rows++; } \mysqli_free_result($this->result); // Log number of rows the query returned - $this->num_rows = $num_rows; + $this->numRows = $num_rows; // Return number of rows selected - $this->return_val = $this->num_rows; + $this->return_val = $this->numRows; } } } @@ -415,10 +415,10 @@ public function query(string $query, bool $use_prepare = false) $this->log_query("\$db->query(\"$query\")"); // Keep track of the last query for debug.. - $this->last_query = $query; + $this->lastQuery = $query; // Count how many queries there have been - $this->num_queries++; + $this->numQueries++; // Use core file cache function if ($cache = $this->get_cache($query)) { @@ -441,7 +441,7 @@ public function query(string $query, bool $use_prepare = false) if ($this->processQueryResult($query) === false) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->lastError); return false; } @@ -450,7 +450,7 @@ public function query(string $query, bool $use_prepare = false) $this->store_cache($query, $this->is_insert); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $this->return_val; } // query @@ -515,7 +515,7 @@ public function getCharset() } /** - * Returns the last inserted auto-increment + * Returns the last inserted Id - auto generated * * @return int */ @@ -531,7 +531,7 @@ public function beginTransaction() { /* turn autocommit off */ $this->dbh->autocommit(false); - $this->dbh->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); + $this->dbh->begin_transaction(\MYSQLI_TRANS_START_READ_WRITE); $this->isTransactional = true; } diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 593de53a..c0632340 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -5,7 +5,6 @@ namespace ezsql\Database; use Exception; -use ezsql\ezQuery; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; @@ -222,7 +221,7 @@ public function catch_error() $error_str = \substr($error_str, 0, -2); - $this->register_error($error_str . ' ' . $this->last_query); + $this->register_error($error_str . ' ' . $this->lastQuery); return true; } @@ -247,14 +246,14 @@ public function query_prepared(string $query, array $param = null, $isSelect = f try { while ($row = @$stmt->fetch(\PDO::FETCH_ASSOC)) { // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; + $this->lastResult[$num_rows] = (object) $row; $num_rows++; } } catch (\Throwable $ex) { // } - $this->num_rows = $num_rows; + $this->numRows = $num_rows; } $return = ($isSelect) ? $stmt : $result; @@ -290,16 +289,16 @@ private function processResult(string $query, $result = null, bool $isSelect = f $col_count = $result->columnCount(); for ($i = 0; $i < $col_count; $i++) { // Start DEBUG by psc! - $this->col_info[$i] = new \stdClass(); + $this->colInfo[$i] = new \stdClass(); // End DEBUG by psc if ($meta = $result->getColumnMeta($i)) { - $this->col_info[$i]->name = $meta['name']; - $this->col_info[$i]->type = $meta['native_type']; - $this->col_info[$i]->max_length = ''; + $this->colInfo[$i]->name = $meta['name']; + $this->colInfo[$i]->type = $meta['native_type']; + $this->colInfo[$i]->max_length = ''; } else { - $this->col_info[$i]->name = 'undefined'; - $this->col_info[$i]->type = 'undefined'; - $this->col_info[$i]->max_length = ''; + $this->colInfo[$i]->name = 'undefined'; + $this->colInfo[$i]->type = 'undefined'; + $this->colInfo[$i]->max_length = ''; } } @@ -308,7 +307,7 @@ private function processResult(string $query, $result = null, bool $isSelect = f try { while ($row = @$result->fetch(\PDO::FETCH_ASSOC)) { // Store results as an objects within main array - $this->last_result[$num_rows] = (object) $row; + $this->lastResult[$num_rows] = (object) $row; $num_rows++; } } catch (\Throwable $ex) { @@ -316,10 +315,10 @@ private function processResult(string $query, $result = null, bool $isSelect = f } // Log number of rows the query returned - $this->num_rows = empty($num_rows) ? $this->num_rows : $num_rows; + $this->numRows = empty($num_rows) ? $this->numRows : $num_rows; // Return number of rows selected - $this->return_val = $this->num_rows; + $this->return_val = $this->numRows; } } else { $this->is_insert = true; @@ -330,7 +329,7 @@ private function processResult(string $query, $result = null, bool $isSelect = f try { // Take note of the insert_id if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = @$this->dbh->lastInsertId(); + $this->insertId = @$this->dbh->lastInsertId(); } } catch (\Throwable $ex) { // @@ -418,21 +417,21 @@ public function query(string $query, bool $use_prepare = false) $this->log_query("\$db->query(\"$query\")"); // Keep track of the last query for debug.. - $this->last_query = $query; + $this->lastQuery = $query; - $this->num_queries++; + $this->numQueries++; // Start timer - $this->timer_start($this->num_queries); + $this->timer_start($this->numQueries); // Use core file cache function if ($cache = $this->get_cache($query)) { // Keep tack of how long all queries have taken - $this->timer_update_global($this->num_queries); + $this->timer_update_global($this->numQueries); // Trace all queries - if ($this->use_trace_log) { - $this->trace_log[] = $this->debug(false); + if ($this->useTraceLog) { + $this->traceLog[] = $this->debug(false); } return $cache; @@ -460,14 +459,14 @@ public function query(string $query, bool $use_prepare = false) $this->store_cache($query, $this->is_insert); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; // Keep tack of how long all queries have taken - $this->timer_update_global($this->num_queries); + $this->timer_update_global($this->numQueries); // Trace all queries - if ($this->use_trace_log) { - $this->trace_log[] = $this->debug(false); + if ($this->useTraceLog) { + $this->traceLog[] = $this->debug(false); } return $this->return_val; diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index daf90e4b..8449fbe3 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -104,7 +104,7 @@ public function connect( $connect_string = "host=" . $host . " port=" . $port . " dbname=" . $name . " user=" . $user . " password=" . $password; // Try to establish the server database handle - if (!$this->dbh = \pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW)) { + if (!$this->dbh = \pg_connect($connect_string, \PGSQL_CONNECT_FORCE_NEW)) { $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); } else { $this->_connected = true; @@ -190,7 +190,7 @@ private function processQueryResult(string $query, $result = null) // Thx. Rafael Bernal $insert_query = \pg_query("SELECT lastval();"); $insert_row = \pg_fetch_row($insert_query); - $this->insert_id = $insert_row[0]; + $this->insertId = $insert_row[0]; } // Return number for rows affected @@ -210,10 +210,10 @@ private function processQueryResult(string $query, $result = null) // Take note of column info $i = 0; while ($i < @\pg_num_fields($this->result)) { - $this->col_info[$i] = new \stdClass(); - $this->col_info[$i]->name = \pg_field_name($this->result, $i); - $this->col_info[$i]->type = \pg_field_type($this->result, $i); - $this->col_info[$i]->size = \pg_field_size($this->result, $i); + $this->colInfo[$i] = new \stdClass(); + $this->colInfo[$i]->name = \pg_field_name($this->result, $i); + $this->colInfo[$i]->type = \pg_field_type($this->result, $i); + $this->colInfo[$i]->size = \pg_field_size($this->result, $i); $i++; } @@ -224,17 +224,17 @@ private function processQueryResult(string $query, $result = null) */ while ($row = @\pg_fetch_object($this->result)) { // Store results as an objects within main array - $this->last_result[$num_rows] = $row; + $this->lastResult[$num_rows] = $row; $num_rows++; } @\pg_free_result($this->result); } // Log number of rows the query returned - $this->num_rows = $num_rows; + $this->numRows = $num_rows; // Return number of rows selected - $this->return_val = $this->num_rows; + $this->return_val = $this->numRows; } } @@ -277,7 +277,7 @@ public function query(string $query, bool $use_prepare = false) $this->log_query("\$db->query(\"$query\")"); // Keep track of the last query for debug.. - $this->last_query = $query; + $this->lastQuery = $query; // Count how many queries there have been $this->count(true, true); @@ -321,7 +321,7 @@ public function query(string $query, bool $use_prepare = false) $this->store_cache($query, $this->is_insert); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $this->return_val; } // query diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index 462b4cd9..3ef53240 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -12,8 +12,8 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface { + protected $is_insert = false; private $return_val = 0; - private $is_insert = false; private $shortcutUsed = false; private $isTransactional = false; @@ -76,7 +76,7 @@ public function connect($path = '', $name = '') //$this->register_error(\FAILED_CONNECTION); //$this->show_errors ? \trigger_error(\FAILED_CONNECTION, \E_USER_WARNING) : null; } else { - $this->conn_queries = 0; + $this->connQueries = 0; $this->_connected = true; } @@ -204,9 +204,9 @@ private function processQueryResult(string $query, $result = null) if (\preg_match("/^(insert|delete|update|replace)\s+/i", $query)) { $this->_affectedRows = @$this->dbh->changes(); - // Take note of the insert_id + // Take note of the insert id if (\preg_match("/^(insert|replace)\s+/i", $query)) { - $this->insert_id = @$this->dbh->lastInsertRowID(); + $this->insertId = @$this->dbh->lastInsertRowID(); } // Return number of rows affected @@ -216,12 +216,12 @@ private function processQueryResult(string $query, $result = null) } else { // Take note of column info $i = 0; - $this->col_info = array(); + $this->colInfo = array(); while ($i < @$this->result->numColumns()) { - $this->col_info[$i] = new \stdClass; - $this->col_info[$i]->name = $this->result->columnName($i); - $this->col_info[$i]->type = null; - $this->col_info[$i]->max_length = null; + $this->colInfo[$i] = new \stdClass; + $this->colInfo[$i]->name = $this->result->columnName($i); + $this->colInfo[$i]->type = null; + $this->colInfo[$i]->max_length = null; $i++; } @@ -230,15 +230,15 @@ private function processQueryResult(string $query, $result = null) while ($row = @$this->result->fetchArray(\SQLITE3_ASSOC)) { // Store result as an objects within main array $obj = (object) $row; //convert to object - $this->last_result[$num_rows] = $obj; + $this->lastResult[$num_rows] = $obj; $num_rows++; } // Log number of rows the query returned - $this->num_rows = $num_rows; + $this->numRows = $num_rows; // Return number of rows selected - $this->return_val = $this->num_rows; + $this->return_val = $this->numRows; } } @@ -272,7 +272,7 @@ public function query(string $query, bool $use_prepare = false) $this->log_query("\$db->query(\"$query\")"); // Keep track of the last query for debug.. - $this->last_query = $query; + $this->lastQuery = $query; // If there is no existing database connection then try to connect if (!isset($this->dbh) || !$this->dbh) { @@ -298,7 +298,7 @@ public function query(string $query, bool $use_prepare = false) $this->result->finalize(); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $this->return_val; } diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index 693fd514..b9b9ed9d 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -115,7 +115,7 @@ public function connect($user = '', $password = '', $name = '', $host = 'localho $this->register_error(\FAILED_CONNECTION . ' in ' . __FILE__ . ' on line ' . __LINE__); } else { $this->_connected = true; - $this->conn_queries = 0; + $this->connQueries = 0; } return $this->_connected; @@ -191,7 +191,7 @@ private function processQueryResult(string $query, $result = null) if ($identityResultset != false) { $identityRow = @\sqlsrv_fetch($identityResultset); - $this->insert_id = $identityRow[0]; + $this->insertId = $identityRow[0]; } } // Return number of rows affected @@ -215,7 +215,7 @@ private function processQueryResult(string $query, $result = null) } $col->type = $this->get_datatype($col); - $this->col_info[$i++] = $col; + $this->colInfo[$i++] = $col; unset($col); } @@ -225,17 +225,17 @@ private function processQueryResult(string $query, $result = null) while ($row = @\sqlsrv_fetch_object($this->result)) { // Store results as an objects within main array - $this->last_result[$num_rows] = $row; + $this->lastResult[$num_rows] = $row; $num_rows++; } @\sqlsrv_free_stmt($this->result); // Log number of rows the query returned - $this->num_rows = $num_rows; + $this->numRows = $num_rows; // Return number of rows selected - $this->return_val = $this->num_rows; + $this->return_val = $this->numRows; } } catch (\Throwable $ex) { return false; @@ -280,7 +280,7 @@ public function query(string $query, bool $use_prepare = false) $this->log_query("\$db->query(\"$query\")"); // Keep track of the last query for debug.. - $this->last_query = $query; + $this->lastQuery = $query; // Count how many queries there have been $this->count(true, true); @@ -323,7 +323,7 @@ public function query(string $query, bool $use_prepare = false) $this->store_cache($query, $this->is_insert); // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $this->return_val; } @@ -424,7 +424,7 @@ public function get_datatype($col) */ public function disconnect() { - $this->conn_queries = 0; + $this->connQueries = 0; @\sqlsrv_close($this->dbh); $this->_connected = false; } diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 39121e42..50ed4b2c 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -12,12 +12,12 @@ if (!\function_exists('ezFunctions')) { /** - * Initialize and connect a vendor database. + * Initialize and connect a vendor's database. * - * @param mixed $sqlDriver - SQL driver - * @param mixed $connectionSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use - * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|Database\ez_sqlite3|ezsql\Database\ez_mysqli + * @param string $sqlDriver - SQL driver + * @param array $connectionSetting - SQL connection parameters + * @param string $instanceTag - Store the instance for later use + * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|ezsql\Database\ez_sqlite3|ezsql\Database\ez_mysqli */ function database(string $sqlDriver = null, array $connectionSetting = null, string $instanceTag = null) { @@ -25,10 +25,10 @@ function database(string $sqlDriver = null, array $connectionSetting = null, str } /** - * Returns an already initialized database instance that was created an tag. + * Returns an already initialized database instance that was created with an tag. * * @param string $getTag - An stored tag instance - * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|Database\ez_sqlite3|ezsql\Database\ez_mysqli + * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|ezsql\Database\ez_sqlite3|ezsql\Database\ez_mysqli */ function tagInstance(string $getTag = null) { @@ -39,7 +39,7 @@ function tagInstance(string $getTag = null) * Initialize an mysqli database. * * @param array $databaseSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use + * @param string $instanceTag - Store the instance for later use * * @return ezsql\Database\ez_mysqli */ @@ -51,8 +51,8 @@ function mysqlInstance(array $databaseSetting = null, string $instanceTag = null /** * Initialize an pgsql database. * - * @param mixed $databaseSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use + * @param array $databaseSetting - SQL connection parameters + * @param string $instanceTag - Store the instance for later use * * @return ezsql\Database\ez_pgsql */ @@ -64,8 +64,8 @@ function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null /** * Initialize an mssql database. * - * @param mixed $databaseSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use + * @param array $databaseSetting - SQL connection parameters + * @param string $instanceTag - Store the instance for later use * * @return ezsql\Database\ez_sqlsrv */ @@ -77,8 +77,8 @@ function mssqlInstance(array $databaseSetting = null, string $instanceTag = null /** * Initialize an pdo database. * - * @param mixed $databaseSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use + * @param array $databaseSetting - SQL connection parameters + * @param string $instanceTag - Store the instance for later use * * @return ezsql\Database\ez_pdo */ @@ -90,8 +90,8 @@ function pdoInstance(array $databaseSetting = null, string $instanceTag = null) /** * Initialize an sqlite3 database. * - * @param mixed $databaseSetting - SQL connection parameters - * @param mixed $instanceTag - Store the instance for later use + * @param array $databaseSetting - SQL connection parameters + * @param string $instanceTag - Store the instance for later use * * @return ezsql\Database\ez_sqlite3 */ @@ -100,13 +100,18 @@ function sqliteInstance(array $databaseSetting = null, string $instanceTag = nul return database(\SQLITE3, $databaseSetting, $instanceTag); } + /** + * Returns the current global database vendor being used. + * + * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` + */ function getVendor() { return ezSchema::vendor(); } /** - * Convert array to string, and attach '`, `' for separation, if none is provided. + * Convert array to string, and attach '`,`' for separation, if none is provided. * * @return string */ @@ -138,19 +143,19 @@ function column(string $column = null, string $type = null, ...$args) function primary(string $primaryName, ...$primaryKeys) { - array_unshift($primaryKeys, \PRIMARY); + \array_unshift($primaryKeys, \PRIMARY); return column(\CONSTRAINT, $primaryName, ...$primaryKeys); } function foreign(string $foreignName, ...$foreignKeys) { - array_unshift($foreignKeys, \FOREIGN); + \array_unshift($foreignKeys, \FOREIGN); return column(\CONSTRAINT, $foreignName, ...$foreignKeys); } function unique(string $uniqueName, ...$uniqueKeys) { - array_unshift($uniqueKeys, \UNIQUE); + \array_unshift($uniqueKeys, \UNIQUE); return column(\CONSTRAINT, $uniqueName, ...$uniqueKeys); } @@ -558,7 +563,7 @@ function select($table = '', $columns = '*', ...$args) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->selecting($table, $columns, ...$args) + ? $ezQuery->select($table, $columns, ...$args) : false; } diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 02c85f17..fe20ce5a 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -11,7 +11,7 @@ class ezQuery implements ezQueryInterface protected $select_result = true; protected $prepareActive = false; protected $preparedValues = array(); - protected $insert_id = null; + protected $insertId = null; private $fromTable = null; private $isWhere = true; @@ -397,7 +397,7 @@ private function flattenWhereConditions($whereConditions) $whereConditionsReturn = []; foreach ($whereConditions as $whereCondition) { if (!empty($whereCondition[0]) && is_array($whereCondition[0])) { - $whereConditionsReturn = array_merge($whereConditionsReturn, $this->flattenWhereConditions($whereCondition)); + $whereConditionsReturn = \array_merge($whereConditionsReturn, $this->flattenWhereConditions($whereCondition)); } else { $whereConditionsReturn[] = $whereCondition; } @@ -462,19 +462,16 @@ public function grouping(...$whereConditions) return false; $whereOrHaving = ($this->isWhere) ? 'WHERE' : 'HAVING'; - if (\is_string($whereConditions[0]) && \strpos($whereConditions[0], $whereOrHaving) !== false) return $whereConditions[0]; - $totalConditions = count($whereConditions) - 1; - + $totalConditions = \count($whereConditions) - 1; if ($totalConditions > 0) { + if (!\in_array('(', $whereConditions[0])) + $whereConditions[0][\count($whereConditions[0])] = '('; - if (!in_array('(', $whereConditions[0])) - $whereConditions[0][count($whereConditions[0])] = '('; - - if (!in_array(')', $whereConditions[$totalConditions])) - $whereConditions[$totalConditions][count($whereConditions[$totalConditions])] = ')'; + if (!\in_array(')', $whereConditions[$totalConditions])) + $whereConditions[$totalConditions][\count($whereConditions[$totalConditions])] = ')'; } return $whereConditions; @@ -525,7 +522,7 @@ public function where(...$whereConditions) return ($where != '1') ? " $whereOrHaving $where " : ' '; } - public function selecting(string $table = null, $columnFields = '*', ...$conditions) + public function select(string $table = null, $columnFields = '*', ...$conditions) { $getFromTable = $this->fromTable; $getSelect_result = $this->select_result; @@ -615,13 +612,13 @@ public function selecting(string $table = null, $columnFields = '*', ...$conditi } /** - * Get SQL statement string from selecting method instead of executing get_result + * Get SQL statement string from `select` method instead of executing get_result * @return string */ private function select_sql($table = '', $columnFields = '*', ...$conditions) { $this->select_result = false; - return $this->selecting($table, $columnFields, ...$conditions); + return $this->select($table, $columnFields, ...$conditions); } public function union(string $table = null, $columnFields = '*', ...$conditions) @@ -762,7 +759,7 @@ private function _query_insert_replace($table = '', $keyAndValue = null, $type = $ok = $this->query($sql); if ($ok) - return $this->insert_id; + return $this->insertId; return $this->clearPrepare(); } else { diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 6ce44b58..38fa8f59 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -386,7 +386,7 @@ public function where(...$whereConditions); * * @return mixed result set - see docs for more details, or false for error */ - public function selecting(string $table = null, $columnFields = '*', ...$conditions); + public function select(string $table = null, $columnFields = '*', ...$conditions); /** * Does an create select statement by calling selecting method diff --git a/lib/ezResultset.php b/lib/ezResultset.php index 6e17783a..df7e5002 100644 --- a/lib/ezResultset.php +++ b/lib/ezResultset.php @@ -54,7 +54,7 @@ class ezResultset implements \Iterator */ public function __construct($query_result) { - if (!is_array($query_result)) { + if (!\is_array($query_result)) { throw new \Exception("$query_result is not valid."); } $this->_resultset = $query_result; diff --git a/lib/ezSchema.php b/lib/ezSchema.php index 2617ab04..1031c5d1 100644 --- a/lib/ezSchema.php +++ b/lib/ezSchema.php @@ -157,22 +157,27 @@ public function __call($type, $args) return $data; } + /** + * Returns the current global database vendor being used. + * + * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` + */ public static function vendor() { $type = null; $instance = getInstance(); if ($instance instanceof DatabaseInterface) { $type = $instance->settings()->getDriver(); - if ($type == \Pdo) { + if ($type === \Pdo) { $type = null; $dbh = $instance->handle(); - if (strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'mysql') !== false) + if (\strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'mysql') !== false) $type = \MYSQL; - elseif (strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'pgsql') !== false) + elseif (\strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'pgsql') !== false) $type = \POSTGRESQL; - elseif (strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'sqlite') !== false) + elseif (\strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'sqlite') !== false) $type = \SQLITE3; - elseif (strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'sqlsrv') !== false) + elseif (\strpos($dbh->getAttribute(\PDO::ATTR_CLIENT_VERSION), 'sqlsrv') !== false) $type = \SQLSERVER; } } diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 679d3f48..3dfb5559 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -23,34 +23,34 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface * If set to true (i.e. $db->debug_all = true;) Then it will print out ALL queries and ALL results of your script. * @var boolean */ - protected $debug_all = false; + protected $debugAll = false; // same as $debug_all protected $trace = false; - protected $debug_called = false; - protected $varDump_called = false; + protected $debugCalled = false; + protected $varDumpCalled = false; /** * Current show error state * @var boolean */ - protected $show_errors = true; + protected $showErrors = true; /** * Keeps track of exactly how many 'real' (not cached) * queries were executed during the lifetime of the current script * @var int */ - protected $num_queries = 0; + protected $numQueries = 0; - protected $conn_queries = 0; - protected $captured_errors = array(); + protected $connQueries = 0; + protected $capturedErrors = array(); /** * Specify a cache dir. Path is taken from calling script * @var string */ - protected $cache_dir = 'tmp' . \_DS . 'ez_cache'; + protected $cacheDir = 'tmp' . \_DS . 'ez_cache'; /** * Disk Cache Setup @@ -60,13 +60,13 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface * Global override setting to turn disc caching off (but not on) * @var boolean */ - protected $use_disk_cache = false; + protected $useDiskCache = false; /** * Cache expiry, this is hours * @var int */ - protected $cache_timeout = 24; + protected $cacheTimeout = 24; /** * if you want to cache EVERYTHING just do.. @@ -81,66 +81,66 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface * is NOT to cache unless specified * @var boolean */ - protected $cache_queries = false; - protected $cache_inserts = false; + protected $cacheQueries = false; + protected $cacheInserts = false; /** * Log number of rows the query returned * @var int Default is null */ - protected $num_rows = null; + protected $numRows = null; - protected $db_connect_time = 0; - protected $sql_log_file = false; - protected $profile_times = array(); + protected $dbConnectTime = 0; + protected $sqlLogFile = false; + protected $profileTimes = array(); /** * ID generated from the AUTO_INCREMENT of the previous INSERT operation (if any) * @var int */ - protected $insert_id = null; + protected $insertId = null; /** * Use to keep track of the last query for debug.. * @var string */ - protected $last_query = null; + protected $lastQuery = null; /** * Use to keep track of last error * @var string */ - protected $last_error = null; + protected $lastError = null; /** * Saved info on the table column * @var mixed */ - protected $col_info = array(); + protected $colInfo = array(); protected $timers = array(); - protected $total_query_time = 0; - protected $trace_log = array(); - protected $use_trace_log = false; - protected $do_profile = false; + protected $totalQueryTime = 0; + protected $traceLog = array(); + protected $useTraceLog = false; + protected $doProfile = false; /** * The last query result * @var object Default is null */ - protected $last_result = null; + protected $lastResult = null; /** * Get data from disk cache * @var boolean Default is false */ - protected $from_disk_cache = false; + protected $fromDiskCache = false; /** * Needed for echo of debug function * @var boolean Default is false */ - protected $debug_echo_is_on = false; + protected $debugEchoIsOn = false; /** * Whether the database connection is established, or not @@ -158,13 +158,13 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface * Function called * @var string */ - private $func_call; + private $funcCall; /** * All functions called * @var array */ - private $all_func_calls = array(); + private $allFuncCalls = array(); /** * Constructor @@ -178,69 +178,69 @@ public function __construct() * Magic methods for Calling Non-Existent Functions, handling Getters and Setters. * @method set/get{property} - a property that needs to be accessed * - * @method void setDebug_All($args); + * @method void setDebugAll($args); * @method void setTrace($args); - * @method void setDebug_Called($args); - * @method void setVarDump_Called($args); - * @method void setShow_Errors($args); - * @method void setNum_Queries($args); - * @method void setConn_Queries($args); - * @method void setCaptured_Errors($args); - * @method void setCache_Dir($args); - * @method void setUse_Disk_Cache($args); - * @method void setCache_Timeout($args); - * @method void setCache_Queries($args); - * @method void setCache_Inserts($args); - * @method void setNum_Rows($args); - * @method void setDb_Connect_Time($args); - * @method void setSql_Log_File($args); - * @method void setProfile_Times($args); - * @method void setInsert_Id($args); - * @method void setLast_Query($args); - * @method void setLast_Error($args); - * @method void setCol_Info($args); + * @method void setDebugCalled($args); + * @method void setVarDumpCalled($args); + * @method void setShowErrors($args); + * @method void setNumQueries($args); + * @method void setConnQueries($args); + * @method void setCapturedErrors($args); + * @method void setCacheDir($args); + * @method void setUseDiskCache($args); + * @method void setCacheTimeout($args); + * @method void setCacheQueries($args); + * @method void setCacheInserts($args); + * @method void setNumRows($args); + * @method void setDbConnectTime($args); + * @method void setSqlLogFile($args); + * @method void setProfileTimes($args); + * @method void setInsertId($args); + * @method void setLastQuery($args); + * @method void setLastError($args); + * @method void setColInfo($args); * @method void setTimers($args); - * @method void setTotal_Query_Time($args); - * @method void setTrace_Log($args); - * @method void setUse_Trace_Log($args); - * @method void setDo_Profile($args); - * @method void setLast_Result($args); - * @method void setFrom_Disk_Cache($args); - * @method void setDebug_Echo_Is_On($args); - * @method void setFunc_Call($args); - * @method void setAll_Func_Calls($args); + * @method void setTotalQueryTime($args); + * @method void setTraceLog($args); + * @method void setUseTraceLog($args); + * @method void setDoProfile($args); + * @method void setLastResult($args); + * @method void setFromDiskCache($args); + * @method void setDebugEchoIsOn($args); + * @method void setFuncCall($args); + * @method void setAllFuncCalls($args); * - * @method string getDebug_All(); + * @method string getDebugAll(); * @method string getTrace(); - * @method string getDebug_Called(); - * @method string getVarDump_Called(); - * @method string getShow_Errors(); - * @method string getNum_Queries(); - * @method string getConn_Queries(); - * @method string getCaptured_Errors(); - * @method string getCache_Dir(); - * @method string getUse_Disk_Cache(); - * @method string getCache_Timeout(); - * @method string getCache_Queries(); - * @method string getCache_Inserts(); - * @method string getNum_Rows(); - * @method string getDb_Connect_Time(); - * @method string getSql_Log_File(); - * @method string getProfile_Times(); - * @method string getInsert_Id(); - * @method string getLast_Query(); - * @method string getLast_Error(); - * @method string getCol_Info(); + * @method string getDebugCalled(); + * @method string getVarDumpCalled(); + * @method string getShowErrors(); + * @method string getNumQueries(); + * @method string getConnQueries(); + * @method string getCapturedErrors(); + * @method string getCacheDir(); + * @method string getUseDiskCache(); + * @method string getCacheTimeout(); + * @method string getCacheQueries(); + * @method string getCacheInserts(); + * @method string getNumRows(); + * @method string getDbConnectTime(); + * @method string getSqlLogFile(); + * @method string getProfileTimes(); + * @method string getInsertId(); + * @method string getLastQuery(); + * @method string getLastError(); + * @method string getColInfo(); * @method string getTimers(); - * @method string getTotal_Query_Time(); - * @method string getTrace_Log(); - * @method string getUse_Trace_Log(); - * @method string getDo_Profile(); - * @method string getLast_Result(); - * @method string getFrom_Disk_Cache(); - * @method string getDebug_Echo_Is_On(); - * @method string getFunc_Call(); - * @method string getAll_Func_Calls(); + * @method string getTotalQueryTime(); + * @method string getTraceLog(); + * @method string getUseTraceLog(); + * @method string getDoProfile(); + * @method string getLastResult(); + * @method string getFromDiskCache(); + * @method string getDebugEchoIsOn(); + * @method string getFuncCall(); + * @method string getAllFuncCalls(); * * @property-read function * @property-write args @@ -251,10 +251,10 @@ public function __construct() public function __call($function, $args) { $prefix = \substr($function, 0, 3); - $property = \strtolower(substr($function, 3, \strlen($function))); + $property = \strtolower(\substr($function, 3, \strlen($function))); // Todo: make properties PSR-1, add following for backward compatibility - //if (\strpos($property, '_') !== false) - // $property = \str_replace('_', '', $property); + if (\strpos($property, '_') !== false) + $property = \str_replace('_', '', $property); if (($prefix == 'set') && \property_exists($this, $property)) { $this->$property = $args[0]; @@ -278,15 +278,15 @@ public function get_host_port(string $host, bool $default = false) public function register_error(string $err_str, bool $displayError = true) { // Keep track of last error - $this->last_error = $err_str; + $this->lastError = $err_str; // Capture all errors to an error array no matter what happens - $this->captured_errors[] = array( + $this->capturedErrors[] = array( 'error_str' => $err_str, - 'query' => $this->last_query + 'query' => $this->lastQuery ); - if ($this->show_errors && $displayError) + if ($this->showErrors && $displayError) \trigger_error(\htmlentities($err_str), \E_USER_WARNING); return false; @@ -294,12 +294,12 @@ public function register_error(string $err_str, bool $displayError = true) public function show_errors() { - $this->show_errors = true; + $this->showErrors = true; } public function hide_errors() { - $this->show_errors = false; + $this->showErrors = false; } /** @@ -307,7 +307,7 @@ public function hide_errors() */ public function debugOn() { - $this->debug_echo_is_on = true; + $this->debugEchoIsOn = true; } /** @@ -315,27 +315,27 @@ public function debugOn() */ public function debugOff() { - $this->debug_echo_is_on = false; + $this->debugEchoIsOn = false; } public function flush() { // Get rid of these - $this->last_result = null; - $this->col_info = array(); - $this->last_query = null; - $this->all_func_calls = array(); - $this->from_disk_cache = false; + $this->lastResult = null; + $this->colInfo = array(); + $this->lastQuery = null; + $this->allFuncCalls = array(); + $this->fromDiskCache = false; $this->clearPrepare(); } public function log_query(string $query) { // Log how the last function was called - $this->func_call = $query; + $this->funcCall = $query; // Keep an running Log of all functions called - \array_push($this->all_func_calls, $this->func_call); + \array_push($this->allFuncCalls, $this->funcCall); } public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false) @@ -349,15 +349,15 @@ public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_ } // Extract public out of cached results based x,y values - if (isset($this->last_result[$y])) { - $values = \array_values(\get_object_vars($this->last_result[$y])); + if (isset($this->lastResult[$y])) { + $values = \array_values(\get_object_vars($this->lastResult[$y])); } // If there is a value return it else return null return (isset($values[$x]) && $values[$x] !== null) ? $values[$x] : null; } - public function get_row(string $query = null, $output = OBJECT, int $y = 0, bool $use_prepare = false) + public function get_row(string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_row(\"$query\",$output,$y)"); @@ -369,16 +369,16 @@ public function get_row(string $query = null, $output = OBJECT, int $y = 0, bool if ($output == OBJECT) { // If the output is an object then return object using the row offset.. - return isset($this->last_result[$y]) ? $this->last_result[$y] : null; - } elseif ($output == ARRAY_A) { + return isset($this->lastResult[$y]) ? $this->lastResult[$y] : null; + } elseif ($output == \ARRAY_A) { // If the output is an associative array then return row as such.. - return isset($this->last_result[$y]) ? \get_object_vars($this->last_result[$y]) : null; - } elseif ($output == ARRAY_N) { + return isset($this->lastResult[$y]) ? \get_object_vars($this->lastResult[$y]) : null; + } elseif ($output == \ARRAY_N) { // If the output is an numerical array then return row as such.. - return isset($this->last_result[$y]) ? \array_values(\get_object_vars($this->last_result[$y])) : null; + return isset($this->lastResult[$y]) ? \array_values(\get_object_vars($this->lastResult[$y])) : null; } else { // If invalid output type was specified.. - $this->show_errors ? \trigger_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N", \E_USER_WARNING) : null; + $this->showErrors ? \trigger_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N", \E_USER_WARNING) : null; } } @@ -392,8 +392,8 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa } // Extract the column values - if (\is_array($this->last_result)) { - $j = \count($this->last_result); + if (\is_array($this->lastResult)) { + $j = \count($this->lastResult); for ($i = 0; $i < $j; $i++) { $new_array[$i] = $this->get_var(null, $x, $i, $use_prepare); } @@ -413,16 +413,16 @@ public function get_results(string $query = null, $output = \OBJECT, bool $use_p } if ($output == OBJECT) { - return $this->last_result; + return $this->lastResult; } elseif ($output == \_JSON) { - return \json_encode($this->last_result); // return as json output - } elseif ($output == ARRAY_A || $output == ARRAY_N) { + return \json_encode($this->lastResult); // return as json output + } elseif ($output == \ARRAY_A || $output == \ARRAY_N) { $new_array = []; - if ($this->last_result) { + if ($this->lastResult) { $i = 0; - foreach ($this->last_result as $row) { + foreach ($this->lastResult as $row) { $new_array[$i] = \get_object_vars($row); - if ($output == ARRAY_N) { + if ($output == \ARRAY_N) { $new_array[$i] = \array_values($new_array[$i]); } $i++; @@ -434,11 +434,11 @@ public function get_results(string $query = null, $output = \OBJECT, bool $use_p public function get_col_info(string $info_type = "name", int $col_offset = -1) { - if ($this->col_info) { + if ($this->colInfo) { $new_array = []; if ($col_offset == -1) { $i = 0; - foreach ($this->col_info as $col) { + foreach ($this->colInfo as $col) { $new_array[$i] = $col->{$info_type}; $i++; } @@ -446,15 +446,15 @@ public function get_col_info(string $info_type = "name", int $col_offset = -1) return $new_array; } - return $this->col_info[$col_offset]->{$info_type}; + return $this->colInfo[$col_offset]->{$info_type}; } } public function create_cache(string $path = null) { - $cache_dir = empty($path) ? $this->cache_dir : $path; + $cache_dir = empty($path) ? $this->cacheDir : $path; if (!\is_dir($cache_dir)) { - $this->cache_dir = $cache_dir; + $this->cacheDir = $cache_dir; @\mkdir($cache_dir, ('\\' == \DIRECTORY_SEPARATOR ? null : 0755), true); } } @@ -462,23 +462,23 @@ public function create_cache(string $path = null) public function store_cache(string $query, bool $is_insert = false) { // The would be cache file for this query - $cache_file = $this->cache_dir . \_DS . \md5($query); + $cache_file = $this->cacheDir . \_DS . \md5($query); // disk caching of queries if ( - $this->use_disk_cache - && ($this->cache_queries && !$is_insert) || ($this->cache_inserts && $is_insert) + $this->useDiskCache + && ($this->cacheQueries && !$is_insert) || ($this->cacheInserts && $is_insert) ) { $this->create_cache(); - if (!\is_dir($this->cache_dir)) { - return $this->register_error("Could not open cache dir: $this->cache_dir"); + if (!\is_dir($this->cacheDir)) { + return $this->register_error("Could not open cache dir: $this->cacheDir"); } else { // Cache all result values $result_cache = array( - 'col_info' => $this->col_info, - 'last_result' => $this->last_result, - 'num_rows' => $this->num_rows, - 'return_value' => $this->num_rows, + 'col_info' => $this->colInfo, + 'last_result' => $this->lastResult, + 'num_rows' => $this->numRows, + 'return_value' => $this->numRows, ); \file_put_contents($cache_file, \serialize($result_cache)); @@ -491,12 +491,12 @@ public function store_cache(string $query, bool $is_insert = false) public function get_cache(string $query) { // The would be cache file for this query - $cache_file = $this->cache_dir . \_DS . \md5($query); + $cache_file = $this->cacheDir . \_DS . \md5($query); // Try to get previously cached version - if ($this->use_disk_cache && \file_exists($cache_file)) { + if ($this->useDiskCache && \file_exists($cache_file)) { // Only use this cache file if less than 'cache_timeout' (hours) - if ((\time() - \filemtime($cache_file)) > ($this->cache_timeout * 3600) + if ((\time() - \filemtime($cache_file)) > ($this->cacheTimeout * 3600) && !(\file_exists($cache_file . ".updating") && (\time() - \filemtime($cache_file . ".updating") < 60)) ) { @@ -504,14 +504,14 @@ public function get_cache(string $query) } else { $result_cache = \unserialize(\file_get_contents($cache_file)); - $this->col_info = $result_cache['col_info']; - $this->last_result = $result_cache['last_result']; - $this->num_rows = $result_cache['num_rows']; + $this->colInfo = $result_cache['col_info']; + $this->lastResult = $result_cache['last_result']; + $this->numRows = $result_cache['num_rows']; - $this->from_disk_cache = true; + $this->fromDiskCache = true; // If debug ALL queries - $this->trace || $this->debug_all ? $this->debug() : null; + $this->trace || $this->debugAll ? $this->debug() : null; return $result_cache['return_value']; } @@ -526,24 +526,24 @@ public function varDump($mixed = null) echo "

"; echo "
";
 
-		if (!$this->varDump_called) {
-			echo "ezSQL (v" . EZSQL_VERSION . ") Variable Dump..\n\n";
+		if (!$this->varDumpCalled) {
+			echo "ezSQL (v" . \EZSQL_VERSION . ") Variable Dump..\n\n";
 		}
 
 		$var_type = \gettype($mixed);
 		\print_r(($mixed ? $mixed : "No Value / False"));
 		echo "\n\nType: " . \ucfirst($var_type) . "\n";
-		echo "Last Query [$this->num_queries]: " . ($this->last_query ? $this->last_query : "NULL") . "\n";
-		echo "Last Function Call: " . ($this->func_call ? $this->func_call : "None") . "\n";
+		echo "Last Query [$this->numQueries]: " . ($this->lastQuery ? $this->lastQuery : "NULL") . "\n";
+		echo "Last Function Call: " . ($this->funcCall ? $this->funcCall : "None") . "\n";
 
-		if (\count($this->all_func_calls) > 1) {
+		if (\count($this->allFuncCalls) > 1) {
 			echo "List of All Function Calls:
"; - foreach ($this->all_func_calls as $func_string) + foreach ($this->allFuncCalls as $func_string) echo " " . $func_string . "
\n"; } echo "Last Rows Returned:
"; - echo ((!empty($this->last_result) && \count($this->last_result) > 0) ? print_r($this->last_result[0]) : 'No rows returned') . "\n"; + echo ((!empty($this->lastResult) && \count($this->lastResult) > 0) ? print_r($this->lastResult[0]) : 'No rows returned') . "\n"; echo "
"; //.$this->donation(); echo "\n


"; @@ -552,11 +552,11 @@ public function varDump($mixed = null) \ob_end_clean(); // Only echo output if it is turned on - if ($this->debug_echo_is_on) { + if ($this->debugEchoIsOn) { echo $html; } - $this->varDump_called = true; + $this->varDumpCalled = true; return $html; } @@ -577,54 +577,54 @@ public function debug($print_to_screen = true) echo "\n\n
"; // Only show ezSQL credits once.. - if (!$this->debug_called) { - echo "ezSQL (v" . EZSQL_VERSION . ")\n Debug.. \n

"; + if (!$this->debugCalled) { + echo "ezSQL (v" . \EZSQL_VERSION . ")\n Debug.. \n

"; } - if ($this->last_error) { - echo "Last Error -- [$this->last_error \n]

"; + if ($this->lastError) { + echo "Last Error -- [$this->lastError \n]

"; } - if ($this->from_disk_cache) { + if ($this->fromDiskCache) { echo "Results retrieved from disk cache

\n"; } - echo "Query [$this->num_queries] \n--"; - echo "[$this->last_query \n]

"; + echo "Query [$this->numQueries] \n--"; + echo "[$this->lastQuery \n]

"; echo "Query Result..\n"; echo "

\n"; - if ($this->col_info) { + if ($this->colInfo) { // Results top rows echo "\n"; echo "\n"; - for ($i = 0, $j = count($this->col_info); $i < $j; $i++) { + for ($i = 0, $j = count($this->colInfo); $i < $j; $i++) { echo ""; } echo "\n"; // print main results - if ($this->last_result) { + if ($this->lastResult) { $i = 0; - foreach ($this->get_results(null, ARRAY_N) as $one_row) { + foreach ($this->get_results(null, \ARRAY_N) as $one_row) { $i++; echo ""; @@ -635,7 +635,7 @@ public function debug($print_to_screen = true) } } else { // if last result - echo "\n"; + echo "\n"; } echo "
(row)\n"; - /* when selecting count(*) the maxlengh is not set, size is set instead. */ - if (isset($this->col_info[$i]->type)) - echo "{$this->col_info[$i]->type}"; + /* when `select` count(*) the maxlengh is not set, size is set instead. */ + if (isset($this->colInfo[$i]->type)) + echo "{$this->colInfo[$i]->type}"; - if (isset($this->col_info[$i]->size)) - echo "{$this->col_info[$i]->size}"; + if (isset($this->colInfo[$i]->size)) + echo "{$this->colInfo[$i]->size}"; - if (isset($this->col_info[$i]->max_length)) - echo "{$this->col_info[$i]->max_length}"; + if (isset($this->colInfo[$i]->max_length)) + echo "{$this->colInfo[$i]->max_length}"; echo "\n
"; - if (isset($this->col_info[$i]->name)) - echo "{$this->col_info[$i]->name}"; + if (isset($this->colInfo[$i]->name)) + echo "{$this->colInfo[$i]->name}"; echo "\n
$i \n
No Results
No Results
\n"; @@ -651,11 +651,11 @@ public function debug($print_to_screen = true) \ob_end_clean(); // Only echo output if it is turned on - if ($this->debug_echo_is_on && $print_to_screen) { + if ($this->debugEchoIsOn && $print_to_screen) { echo $html; } - $this->debug_called = true; + $this->debugCalled = true; return $html; } @@ -678,20 +678,20 @@ public function timer_elapsed($timer_name) public function timer_update_global($timer_name) { - if ($this->do_profile) { - $this->profile_times[] = array( - 'query' => $this->last_query, + if ($this->doProfile) { + $this->profileTimes[] = array( + 'query' => $this->lastQuery, 'time' => $this->timer_elapsed($timer_name) ); } - $this->total_query_time += $this->timer_elapsed($timer_name); + $this->totalQueryTime += $this->timer_elapsed($timer_name); } public function count($all = true, $increase = false) { if ($increase) { - $this->num_queries++; - $this->conn_queries++; + $this->numQueries++; + $this->connQueries++; } return ($all) ? $this->num_queries : $this->conn_queries; @@ -756,6 +756,6 @@ public function affectedRows() */ public function queryResult() { - return $this->last_result; + return $this->lastResult; } } // ezsqlModel diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 171e5f26..3e85c6f9 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -140,7 +140,7 @@ public function get_results(string $query = null, $output = \OBJECT, bool $use_p * - If no column offset is supplied then a one dimensional array is returned with the * information type for ‘all columns’. * - For access to the full meta information for all columns you can use the cached - * variable `$db->col_info`, access by calling `$db->getCol_Info()` + * variable `$db->colInfo`, access by calling `$db->getCol_Info()` * * Available Info-Types: * mySQL diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index b5deca6d..17d2016d 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -23,7 +23,7 @@ public function testInitialize() ); } - $mysqli = Database::initialize(MYSQLI, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME], MYSQLI); + $mysqli = Database::initialize(\MYSQLI, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME], MYSQLI); $this->assertFalse($mysqli instanceof ConfigInterface); $this->assertTrue($mysqli->settings() instanceof ConfigInterface); $this->assertTrue($mysqli instanceof ez_mysqli); @@ -41,7 +41,7 @@ public function testInitialize_Pgsql() ); } - $pgsql = Database::initialize(PGSQL, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]); + $pgsql = Database::initialize(\PGSQL, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]); $this->assertFalse($pgsql instanceof ConfigInterface); $this->assertTrue($pgsql->settings() instanceof ConfigInterface); $this->assertTrue($pgsql instanceof ez_pgsql); @@ -58,7 +58,7 @@ public function testInitialize_Sqlite3() ); } - $sqlite3 = Database::initialize(SQLITE3, [self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]); + $sqlite3 = Database::initialize(\SQLITE3, [self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]); $this->assertFalse($sqlite3 instanceof ConfigInterface); $this->assertTrue($sqlite3->settings() instanceof ConfigInterface); $this->assertTrue($sqlite3 instanceof ez_sqlite3); @@ -75,7 +75,7 @@ public function testInitialize_Sqlsrv() ); } - $sqlsrv = Database::initialize(SQLSERVER, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); + $sqlsrv = Database::initialize(\SQLSERVER, [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); $this->assertFalse($sqlsrv instanceof ConfigInterface); $this->assertTrue($sqlsrv->settings() instanceof ConfigInterface); $this->assertTrue($sqlsrv instanceof ez_sqlsrv); diff --git a/tests/ezQueryTest.php b/tests/ezQueryTest.php index 3aacdeab..de6c6a42 100644 --- a/tests/ezQueryTest.php +++ b/tests/ezQueryTest.php @@ -108,10 +108,10 @@ public function testDelete() $this->assertFalse($this->object->delete('test_unit_delete', array('good', 'bad'))); } - public function testSelecting() + public function testSelect() { - $this->assertFalse($this->object->selecting('', '')); - $this->assertNotNull($this->object->selecting('table', 'columns', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT')); + $this->assertFalse($this->object->select('', '')); + $this->assertNotNull($this->object->select('table', 'columns', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT')); } public function testCreate_select() diff --git a/tests/ezsqlModelTest.php b/tests/ezsqlModelTest.php index 55c28d0f..c41a46d1 100644 --- a/tests/ezsqlModelTest.php +++ b/tests/ezsqlModelTest.php @@ -30,7 +30,7 @@ public function testGet_host_port() public function testGetCache_Timeout() { - $res = $this->object->getCache_Timeout(); + $res = $this->object->getCacheTimeout(); $this->assertEquals(24, $res); } @@ -161,7 +161,7 @@ public function testGet_cache() public function testVarDump() { $this->object->setDebug_Echo_Is_On(false); - $this->object->setLast_Result(['test 1']); + $this->object->setLastResult(['test 1']); $this->assertNotEmpty($this->object->varDump($this->object->getLast_Result())); $this->object->setDebug_Echo_Is_On(true); $this->expectOutputRegex('/[Last Function Call]/'); @@ -170,8 +170,8 @@ public function testVarDump() public function testDump_var() { - $this->object->setDebug_Echo_Is_On(true); - $this->object->setLast_Result(['Test 1', 'Test 2']); + $this->object->setDebugEchoIsOn(true); + $this->object->setLastResult(['Test 1', 'Test 2']); $this->expectOutputRegex('/[Last Function Call]/'); $this->object->dump_var(); } @@ -182,15 +182,15 @@ public function testDebug() $this->assertNotEmpty($this->object->debug(false)); // In addition of getting a result, it fills the console - $this->object->setLast_Error("test last"); + $this->object->setLastError("test last"); $this->expectOutputRegex('/[test last]/'); $this->object->debug(); - $this->object->setFrom_Disk_Cache(true); + $this->object->setFromDiskCache(true); $this->expectOutputRegex('/[Results retrieved from disk cache]/'); $this->object->debug(); - $this->object->setCol_Info(["just another test"]); + $this->object->setColInfo(["just another test"]); $this->object->debug(false); - $this->object->setCol_Info(null); + $this->object->setColInfo(null); $this->object->setLast_Result(["just another test II"]); $this->object->debug(false); } @@ -222,9 +222,9 @@ public function testTimer_update_global() { $this->object->timer_start('test_timer'); usleep(5); - $this->object->setDo_Profile(true); + $this->object->setDoProfile(true); $this->object->timer_update_global('test_timer'); - $expected = $this->object->getTotal_Query_Time(); + $expected = $this->object->getTotalQueryTime(); $this->assertGreaterThanOrEqual($expected, $this->object->timer_elapsed('test_timer')); } diff --git a/tests/mysqli/ezResultsetTest.php b/tests/mysqli/ezResultsetTest.php index 66191e3a..75003413 100644 --- a/tests/mysqli/ezResultsetTest.php +++ b/tests/mysqli/ezResultsetTest.php @@ -48,7 +48,7 @@ protected function setUp(): void $this->database->insert('unit_test', ['id' => 4, 'test_key' => 'test 4']); $this->database->insert('unit_test', ['id' => 5, 'test_key' => 'test 5']); - $this->database->selecting('unit_test'); + $this->database->select('unit_test'); $this->object = new ezResultset($this->database->get_results()); } // setUp diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 6c7ae924..de87fa30 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -75,7 +75,7 @@ protected function setUp(): void protected function tearDown(): void { if ($this->object->isConnected()) { - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->assertEquals($this->object->drop('unit_test'), 0); } $this->object = null; @@ -112,26 +112,25 @@ public function testConnect() $this->assertTrue($result); } - public function testSelect() + public function testDbSelect() { $this->object->connect(); $this->assertTrue($this->object->isConnected()); - $result = $this->object->select(self::TEST_DB_NAME); + $result = $this->object->dbSelect(self::TEST_DB_NAME); $this->assertTrue($result); $this->errors = array(); - set_error_handler(array($this, 'errorHandler')); - $this->assertTrue($this->object->select('')); + $this->assertTrue($this->object->dbSelect('')); $this->object->disconnect(); - $this->assertFalse($this->object->select('notest')); + $this->assertFalse($this->object->dbSelect('notest')); $this->object->connect(); $this->object->reset(); - $this->assertFalse($this->object->select(self::TEST_DB_NAME)); + $this->assertFalse($this->object->dbSelect(self::TEST_DB_NAME)); $this->object->connect(); - $this->assertFalse($this->object->select('notest')); - $this->assertTrue($this->object->select(self::TEST_DB_NAME)); + $this->assertFalse($this->object->dbSelect('notest')); + $this->assertTrue($this->object->dbSelect(self::TEST_DB_NAME)); } public function testEscape() @@ -151,7 +150,7 @@ public function testQueryInsert() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->assertEquals(0, $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))')); @@ -168,7 +167,7 @@ public function testQuerySelect() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->assertEquals($this->object->query('DROP TABLE IF EXISTS unit_test'), 0); $this->assertEquals($this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'), 0); @@ -219,7 +218,7 @@ public function testGetCharset() public function testDisconnect() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->assertNotNull($this->object->handle()); $this->object->disconnect(); $this->assertFalse($this->object->isConnected()); @@ -230,7 +229,7 @@ public function testDisconnect() public function testGetInsertId() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->assertEquals($this->object->query('CREATE TABLE unit_test(id int(11) NOT NULL AUTO_INCREMENT, test_key varchar(50), PRIMARY KEY (ID))ENGINE=MyISAM DEFAULT CHARSET=utf8'), 0); $this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(1, \'test 1\')'), 1); @@ -349,17 +348,17 @@ public function testDelete() $this->assertEquals(1, $this->object->delete('unit_test', $where)); } - public function testSelecting() + public function testSelect() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); - $this->object->select(self::TEST_DB_NAME); + $this->object->dbSelect(self::TEST_DB_NAME); $this->object->query('CREATE TABLE unit_test(id int(11) NOT NULL AUTO_INCREMENT, test_key varchar(50), PRIMARY KEY (ID))ENGINE=MyISAM DEFAULT CHARSET=utf8'); $this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1')); $this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { @@ -369,17 +368,17 @@ public function testSelecting() } $where = ['test_key', '=', 'testing 2']; - $result = $this->object->selecting('unit_test', 'id', $where); + $result = $this->object->select('unit_test', 'id', $where); foreach ($result as $row) { $this->assertEquals(2, $row->id); } - $result = $this->object->selecting('unit_test', 'test_key', ['id', '=', 3]); + $result = $this->object->select('unit_test', 'test_key', ['id', '=', 3]); foreach ($result as $row) { $this->assertEquals('testing 3', $row->test_key); } - $result = $this->object->selecting('unit_test', array('test_key'), "id = 1"); + $result = $this->object->select('unit_test', array('test_key'), "id = 1"); foreach ($result as $row) { $this->assertEquals('testing 1', $row->test_key); } @@ -406,7 +405,7 @@ public function testBeginTransactionCommit() } if ($commit) { - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -439,7 +438,7 @@ public function testBeginTransactionRollback() if ($commit) { echo ("Error! This message shouldn't have been displayed."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals('should not be seen ' . $i, $row->test_key); @@ -448,7 +447,7 @@ public function testBeginTransactionRollback() $this->object->drop('unit_test'); } else { //echo ("Error! rollback."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals('should not be seen ' . $i, $row->test_key); @@ -460,7 +459,7 @@ public function testBeginTransactionRollback() } } - public function testSelectingAndCreateTable() + public function testSelectAndCreateTable() { $this->object->drop('users'); $this->object->create( @@ -501,9 +500,9 @@ public function testSelectingAndCreateTable() ]) ); - $result = $this->object->selecting('users', 'id, tel_num, email', eq('user_name ', 'walker')); + $result = $this->object->select('users', 'id, tel_num, email', eq('user_name ', 'walker')); - $this->object->setDebug_Echo_Is_On(true); + $this->object->setDebugEchoIsOn(true); $this->expectOutputRegex('/[123456]/'); $this->expectOutputRegex('/[walker@email.com]/'); $this->object->debug(); @@ -529,7 +528,7 @@ public function testCreate_select() $this->assertEquals(0, $this->object->create_select('new_new_test', '*', 'unit_test')); - $result = $this->object->selecting('new_new_test'); + $result = $this->object->select('new_new_test'); $i = 1; foreach ($result as $row) { diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index d7234927..ed30fd53 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -244,7 +244,7 @@ public function testDelete() $this->assertEquals(0, $this->object->query('DROP TABLE unit_test')); } - public function testSelecting() + public function testSelect() { $this->assertTrue($this->object->connect('mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); @@ -252,7 +252,7 @@ public function testSelecting() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -266,12 +266,12 @@ public function testSelecting() $this->assertEquals(2, $row->id); } - $result = $this->object->selecting('unit_test', 'test_key', array('id', '=', '3')); + $result = $this->object->select('unit_test', 'test_key', array('id', '=', '3')); foreach ($result as $row) { $this->assertEquals('testing 3', $row->test_key); } - $result = $this->object->selecting('unit_test', array('test_key'), eq('id', 1)); + $result = $this->object->select('unit_test', array('test_key'), eq('id', 1)); foreach ($result as $row) { $this->assertEquals('testing 1', $row->test_key); } @@ -287,7 +287,7 @@ public function testWhereGrouping() $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->select('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -311,7 +311,7 @@ public function testJoins() $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); - $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); + $result = $this->object->select('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; $o = 3; foreach ($result as $row) { @@ -323,7 +323,7 @@ public function testJoins() --$o; } - $result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); + $result = $this->object->select('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); $o = 3; foreach ($result as $row) { $this->assertEquals($o, $row->parent_id); @@ -355,7 +355,7 @@ public function testBeginTransactionCommit() } if ($commit) { - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -388,7 +388,7 @@ public function testBeginTransactionRollback() if ($commit) { echo ("Error! This message shouldn't have been displayed."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals('should not be seen ' . $i, $row->test_key); @@ -397,7 +397,7 @@ public function testBeginTransactionRollback() $this->object->drop('unit_test'); } else { //echo ("Error! rollback."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals('should not be seen ' . $i, $row->test_key); diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 202246e1..27effefb 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -162,7 +162,7 @@ public function testDelete() $this->assertEquals(0, $this->object->query('DROP TABLE unit_test')); } - public function testSelecting() + public function testSelect() { $this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->drop('unit_test'); @@ -171,7 +171,7 @@ public function testSelecting() $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); $this->object->insert('unit_test', array('test_key' => 'test 3', 'test_value' => 'testing string 3')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -181,18 +181,18 @@ public function testSelecting() } $where = eq('id', '2'); - $result = $this->object->selecting('unit_test', 'id', $this->object->where($where)); + $result = $this->object->select('unit_test', 'id', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals(2, $row->id); } $where = [eq('test_value', 'testing string 3', _AND), eq('id', '3')]; - $result = $this->object->selecting('unit_test', 'test_key', $this->object->where($where)); + $result = $this->object->select('unit_test', 'test_key', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals('test 3', $row->test_key); } - $result = $this->object->selecting('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); + $result = $this->object->select('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } @@ -210,7 +210,7 @@ public function testWhereGrouping() $this->object->insert('unit_test_more', array('test_key' => 'testing 3', 'active_data' => 1)); $this->object->insert('unit_test_more', array('test_key' => 'testing 4', 'active_data' => 1)); - $result = $this->object->selecting('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->select('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -234,7 +234,7 @@ public function testJoins() $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); - $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); + $result = $this->object->select('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; $o = 3; foreach ($result as $row) { @@ -246,7 +246,7 @@ public function testJoins() --$o; } - $result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); + $result = $this->object->select('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); $o = 3; foreach ($result as $row) { $this->assertEquals($o, $row->parent_id); diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index acdd1bde..21187faf 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -188,7 +188,7 @@ public function testDelete() $this->assertEquals(1, $this->object->query('DROP TABLE unit_test')); } - public function testSelecting() + public function testSelect() { $this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true)); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); @@ -196,7 +196,7 @@ public function testSelecting() $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); $this->object->insert('unit_test', array('test_key' => 'test 3', 'test_value' => 'testing string 3')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -206,18 +206,18 @@ public function testSelecting() } $where = eq('id', '2'); - $result = $this->object->selecting('unit_test', 'id', $this->object->where($where)); + $result = $this->object->select('unit_test', 'id', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals(2, $row->id); } $where = [eq('test_value', 'testing string 3', _AND), eq('id', '3')]; - $result = $this->object->selecting('unit_test', 'test_key', $this->object->where($where)); + $result = $this->object->select('unit_test', 'test_key', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals('test 3', $row->test_key); } - $result = $this->object->selecting('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); + $result = $this->object->select('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } @@ -234,7 +234,7 @@ public function testWhereGrouping() $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1)); $this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1)); - $result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->select('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -258,7 +258,7 @@ public function testJoins() $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); - $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); + $result = $this->object->select('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; $o = 3; foreach ($result as $row) { @@ -270,7 +270,7 @@ public function testJoins() --$o; } - $result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); + $result = $this->object->select('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); $o = 3; foreach ($result as $row) { $this->assertEquals($o, $row->parent_id); diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index 783845ef..2d4db82d 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -168,7 +168,7 @@ public function testDelete() ); } - public function testSelecting() + public function testSelect() { $this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD)); $this->object->drop('unit_test'); @@ -177,7 +177,7 @@ public function testSelecting() $this->object->insert('unit_test', array('id' => 9, 'test_key' => 'testing 9')); $this->object->insert('unit_test', array('id' => 10, 'test_key' => 'testing 10')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 8; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -186,17 +186,17 @@ public function testSelecting() } $where = eq('test_key', 'testing 10'); - $result = $this->object->selecting('unit_test', 'id', $where); + $result = $this->object->select('unit_test', 'id', $where); foreach ($result as $row) { $this->assertEquals(10, $row->id); } - $result = $this->object->selecting('unit_test', 'test_key', eq('id', 9)); + $result = $this->object->select('unit_test', 'test_key', eq('id', 9)); foreach ($result as $row) { $this->assertEquals('testing 9', $row->test_key); } - $result = $this->object->selecting('unit_test', array('test_key'), ['id', '=', 8]); + $result = $this->object->select('unit_test', array('test_key'), ['id', '=', 8]); foreach ($result as $row) { $this->assertEquals('testing 8', $row->test_key); } @@ -213,7 +213,7 @@ public function testWhereGrouping() $this->object->insert('unit_test_other', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1)); $this->object->insert('unit_test_other', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1)); - $result = $this->object->selecting('unit_test_other', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); + $result = $this->object->select('unit_test_other', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%')))); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -237,7 +237,7 @@ public function testJoins() $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); - $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); + $result = $this->object->select('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; $o = 3; foreach ($result as $row) { @@ -249,7 +249,7 @@ public function testJoins() --$o; } - $result = $this->object->selecting('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); + $result = $this->object->select('unit_test_child', 'child.parent_id', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id', 'child')); $o = 3; foreach ($result as $row) { $this->assertEquals($o, $row->parent_id); diff --git a/tests/postgresql/postgresqlTest.php b/tests/postgresql/postgresqlTest.php index fb9910ea..f7e44093 100644 --- a/tests/postgresql/postgresqlTest.php +++ b/tests/postgresql/postgresqlTest.php @@ -234,7 +234,7 @@ public function testGetPort() $this->assertEquals(self::TEST_DB_PORT, $this->object->getPort()); } - public function testSelecting() + public function testSelect() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT); $this->object->query('CREATE TABLE unit_test(id serial, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); @@ -242,7 +242,7 @@ public function testSelecting() $this->object->insert('unit_test', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); $this->object->insert('unit_test', array('test_key' => 'test 3', 'test_value' => 'testing string 3')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -252,18 +252,18 @@ public function testSelecting() } $where = eq('id', '2'); - $result = $this->object->selecting('unit_test', 'id', $this->object->where($where)); + $result = $this->object->select('unit_test', 'id', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals(2, $row->id); } $where = [eq('test_value', 'testing string 3', _AND), eq('id', '3')]; - $result = $this->object->selecting('unit_test', 'test_key', $this->object->where($where)); + $result = $this->object->select('unit_test', 'test_key', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals('test 3', $row->test_key); } - $result = $this->object->selecting('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); + $result = $this->object->select('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } @@ -290,7 +290,7 @@ public function testBeginTransactionCommit() } if ($commit) { - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -323,7 +323,7 @@ public function testBeginTransactionRollback() if ($commit) { echo ("Error! This message shouldn't have been displayed."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -335,7 +335,7 @@ public function testBeginTransactionRollback() $this->object->drop('unit_test'); } else { //echo ("Error! rollback."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); diff --git a/tests/sqlite/sqlite3Test.php b/tests/sqlite/sqlite3Test.php index 2dcd2f4d..693cb26b 100644 --- a/tests/sqlite/sqlite3Test.php +++ b/tests/sqlite/sqlite3Test.php @@ -219,7 +219,7 @@ public function testDelete() $this->assertEquals(1, $this->object->delete('test_table', $where)); } - public function testSelecting() + public function testSelect() { $this->object->query('CREATE TABLE test_table(id integer, test_key varchar(50), test_value varchar(50), PRIMARY KEY (ID))'); @@ -227,7 +227,7 @@ public function testSelecting() $this->object->insert('test_table', array('test_key' => 'test 2', 'test_value' => 'testing string 2')); $this->object->insert('test_table', array('test_key' => 'test 3', 'test_value' => 'testing string 3')); - $result = $this->object->selecting('test_table'); + $result = $this->object->select('test_table'); $i = 1; foreach ($result as $row) { @@ -238,18 +238,18 @@ public function testSelecting() } $where = eq('id', 2); - $result = $this->object->selecting('test_table', 'id', $this->object->where($where)); + $result = $this->object->select('test_table', 'id', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals(2, $row->id); } $where = [eq('test_value', 'testing string 3')]; - $result = $this->object->selecting('test_table', 'test_key', $this->object->where($where)); + $result = $this->object->select('test_table', 'test_key', $this->object->where($where)); foreach ($result as $row) { $this->assertEquals('test 3', $row->test_key); } - $result = $this->object->selecting('test_table', 'test_value', $this->object->where(eq('test_key', 'test 1'))); + $result = $this->object->select('test_table', 'test_value', $this->object->where(eq('test_key', 'test 1'))); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } @@ -275,7 +275,7 @@ public function testBeginTransactionCommit() } if ($commit) { - $result = $this->object->selecting('test_table'); + $result = $this->object->select('test_table'); $i = 1; foreach ($result as $row) { $this->assertEquals($i, $row->id); @@ -307,7 +307,7 @@ public function testBeginTransactionRollback() if ($commit) { echo ("Error! This message shouldn't have been displayed."); - $result = $this->object->selecting('test_table'); + $result = $this->object->select('test_table'); $i = 1; foreach ($result as $row) { @@ -320,7 +320,7 @@ public function testBeginTransactionRollback() $this->object->drop('test_table'); } else { //echo ("Error! rollback."); - $result = $this->object->selecting('test_table'); + $result = $this->object->select('test_table'); $i = 1; foreach ($result as $row) { diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index cf6003cc..4010c28b 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -233,7 +233,7 @@ public function testDelete() ); } - public function testSelecting() + public function testSelect() { $this->object->quick_connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME); $this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), PRIMARY KEY (ID))'); @@ -242,7 +242,7 @@ public function testSelecting() $this->object->insert('unit_test', array('id' => 9, 'test_key' => 'testing 9')); $this->object->insert('unit_test', array('id' => 10, 'test_key' => 'testing 10')); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 8; foreach ($result as $row) { @@ -252,17 +252,17 @@ public function testSelecting() } $where = eq('test_key', 'testing 10'); - $result = $this->object->selecting('unit_test', 'id', $where); + $result = $this->object->select('unit_test', 'id', $where); foreach ($result as $row) { $this->assertEquals(10, $row->id); } - $result = $this->object->selecting('unit_test', 'test_key', eq('id', 9)); + $result = $this->object->select('unit_test', 'test_key', eq('id', 9)); foreach ($result as $row) { $this->assertEquals('testing 9', $row->test_key); } - $result = $this->object->selecting('unit_test', array('test_key'), eq('id', 8)); + $result = $this->object->select('unit_test', array('test_key'), eq('id', 8)); foreach ($result as $row) { $this->assertEquals('testing 8', $row->test_key); } @@ -288,7 +288,7 @@ public function testBeginTransactionCommit() } if ($commit) { - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 8; foreach ($result as $row) { @@ -321,7 +321,7 @@ public function testBeginTransactionRollback() if ($commit) { echo ("Error! This message shouldn't have been displayed."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 8; foreach ($result as $row) { @@ -333,7 +333,7 @@ public function testBeginTransactionRollback() $this->object->drop('unit_test'); } else { //echo ("Error! rollback."); - $result = $this->object->selecting('unit_test'); + $result = $this->object->select('unit_test'); $i = 8; foreach ($result as $row) { From f4db08c88b30bcf6e66e7e3977ec3ff016696bb8 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 15:25:32 -0500 Subject: [PATCH 138/148] Update ezsqlModel.php --- lib/ezsqlModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 3dfb5559..47ec0d9e 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -251,7 +251,7 @@ public function __construct() public function __call($function, $args) { $prefix = \substr($function, 0, 3); - $property = \strtolower(\substr($function, 3, \strlen($function))); + $property = \lcfirst(\substr($function, 3, \strlen($function))); // Todo: make properties PSR-1, add following for backward compatibility if (\strpos($property, '_') !== false) $property = \str_replace('_', '', $property); From 7731e1d58a599583ceeab797b426a07a3addd131 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 16:20:10 -0500 Subject: [PATCH 139/148] update/bug fix --- .gitignore | 1 + lib/ezsqlModel.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b90a936d..5ae0b967 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ test.php *.crt *.cache tmp +.rnd diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 47ec0d9e..99ba70cf 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -694,7 +694,7 @@ public function count($all = true, $increase = false) $this->connQueries++; } - return ($all) ? $this->num_queries : $this->conn_queries; + return ($all) ? $this->numQueries : $this->connQueries; } public function secureSetup( From cf77e293fa1aee2b6cff05acce05b1d37fca0c4b Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 18:25:57 -0500 Subject: [PATCH 140/148] Update ez_mysqli.php --- lib/Database/ez_mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index d8923bd0..7de25a4f 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -428,7 +428,7 @@ public function query(string $query, bool $use_prepare = false) // If there is no existing database connection then try to connect if (!isset($this->dbh) || !$this->dbh) { $this->connect($this->database->getUser(), $this->database->getPassword(), $this->database->getHost()); - $this->select($this->database->getName()); + $this->dbSelect($this->database->getName()); } // Perform the query via std mysql_query function.. From 3a38e16ea73770ef53297e49d1d17441fcbdf44f Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 18:58:29 -0500 Subject: [PATCH 141/148] Update ezQueryTest.php --- tests/ezQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ezQueryTest.php b/tests/ezQueryTest.php index de6c6a42..bad54f3c 100644 --- a/tests/ezQueryTest.php +++ b/tests/ezQueryTest.php @@ -9,7 +9,7 @@ eq, neq, like, - in, + in }; class ezQueryTest extends EZTestCase From 08b0e6c756c544feffb84a752e63fceb3e539af4 Mon Sep 17 00:00:00 2001 From: techno-express Date: Sat, 13 Feb 2021 20:41:57 -0500 Subject: [PATCH 142/148] tests build bug fix --- tests/ezSchemaTest.php | 2 +- tests/mysqli/ezResultsetTest.php | 2 +- tests/pdo/pdo_mysqlTest.php | 2 +- tests/pdo/pdo_pgsqlTest.php | 2 +- tests/pdo/pdo_sqliteTest.php | 2 +- tests/pdo/pdo_sqlsrvTest.php | 2 +- tests/postgresql/postgresqlTest.php | 2 +- tests/sqlite/sqlite3Test.php | 2 +- tests/sqlsrv/sqlsrvTest.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ezSchemaTest.php b/tests/ezSchemaTest.php index 8f05ac73..1f72075c 100644 --- a/tests/ezSchemaTest.php +++ b/tests/ezSchemaTest.php @@ -14,7 +14,7 @@ getVendor, column, primary, - index, + index }; class ezSchemaTest extends EZTestCase diff --git a/tests/mysqli/ezResultsetTest.php b/tests/mysqli/ezResultsetTest.php index 75003413..91dc7fe3 100644 --- a/tests/mysqli/ezResultsetTest.php +++ b/tests/mysqli/ezResultsetTest.php @@ -7,7 +7,7 @@ use function ezsql\functions\{ mysqlInstance, - column, + column }; class ezResultsetTest extends EZTestCase diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index ed30fd53..d11b2c67 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -17,7 +17,7 @@ grouping, like, where, - eq, + eq }; class pdo_mysqlTest extends EZTestCase diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 27effefb..d5d4abef 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -10,7 +10,7 @@ grouping, like, where, - eq, + eq }; class pdo_pgsqlTest extends EZTestCase diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index 21187faf..84cdf8b7 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -10,7 +10,7 @@ grouping, like, where, - eq, + eq }; class pdo_sqliteTest extends EZTestCase diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index 2d4db82d..2645a68a 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -10,7 +10,7 @@ eq, like, leftJoin, - pdoInstance, + pdoInstance }; class pdo_sqlsrvTest extends EZTestCase diff --git a/tests/postgresql/postgresqlTest.php b/tests/postgresql/postgresqlTest.php index f7e44093..7215caff 100644 --- a/tests/postgresql/postgresqlTest.php +++ b/tests/postgresql/postgresqlTest.php @@ -10,7 +10,7 @@ column, primary, eq, - pgsqlInstance, + pgsqlInstance }; class postgresqlTest extends EZTestCase diff --git a/tests/sqlite/sqlite3Test.php b/tests/sqlite/sqlite3Test.php index 693cb26b..c4cb2a7b 100644 --- a/tests/sqlite/sqlite3Test.php +++ b/tests/sqlite/sqlite3Test.php @@ -11,7 +11,7 @@ column, primary, eq, - sqliteInstance, + sqliteInstance }; /** diff --git a/tests/sqlsrv/sqlsrvTest.php b/tests/sqlsrv/sqlsrvTest.php index 4010c28b..5a6e4877 100644 --- a/tests/sqlsrv/sqlsrvTest.php +++ b/tests/sqlsrv/sqlsrvTest.php @@ -10,7 +10,7 @@ column, primary, eq, - mssqlInstance, + mssqlInstance }; class sqlsrvTest extends EZTestCase From 68e18b8bfdb8dd34939c22db6495e0075143358a Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 14 Feb 2021 21:00:49 -0500 Subject: [PATCH 143/148] updates/corrections, and added feature - call methods without table name - `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters: - The Table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. - This **feature** will be added to **all** database access methods, each method name will have an `ing` ending added. In reference to https://github.com/ezSQL/ezsql/issues/198 --- README.md | 34 +++-- lib/Config.php | 27 ---- lib/Database/ez_pdo.php | 2 +- lib/Database/ez_pgsql.php | 2 +- lib/Database/ez_sqlite3.php | 4 +- lib/Database/ez_sqlsrv.php | 2 +- lib/ezFunctions.php | 273 +++++++++++++++++++++++++++--------- lib/ezQuery.php | 104 +++++++++----- lib/ezQueryInterface.php | 255 +++++++++++++++++++++++++-------- lib/ezsqlModel.php | 169 +++++++++++----------- lib/ezsqlModelInterface.php | 90 +++++++++++- tests/ezFunctionsTest.php | 38 ++++- tests/mysqli/mysqliTest.php | 66 ++++++--- 13 files changed, 750 insertions(+), 316 deletions(-) diff --git a/README.md b/README.md index e591b2c1..8ad8c771 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,27 @@ ***A class to make it very easy to deal with database connections.*** -This is a [WIP] of [__version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**, mainly by the use of `namespace` in the `global` functions **ezFunctions.php** file. - -Usage of the **global** functions will require the user to begin a `.php` file something like: - -```php -use function ezsql\functions\where; -// Or -use function ezsql\functions\{ - getInstance, - select, - insert, -}; -``` +This is a [WIP] of [__version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**. + +Mainly by: + - The use of `namespace` in the `global` functions **ezFunctions.php** file. + Usage of the **global** functions will require the user to begin a `.php` file something like: + + ```php + use function ezsql\functions\where; + // Or + use function ezsql\functions\{ + getInstance, + selecting, + inserting, + }; + ``` + - Class properties that was accessible by magic methods `get/set`, now PSR 1 camelCase. + - Renamed `select` of `ez_mysqli` to `dbSelect`. + - Renamed class method and behavior of `selecting` to `select`. + - `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters: + - The Table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. + - This **feature** will be added to **all** database access methods, each method name will have an `ing` ending added. [__version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. diff --git a/lib/Config.php b/lib/Config.php index 03582005..f2510762 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -8,33 +8,6 @@ use ezsql\ConfigAbstract; use ezsql\ConfigInterface; -/** - * @method void setDriver($args); - * @method void setDsn($args); - * @method void setUser($args); - * @method void setPassword($args); - * @method void setName($args); - * @method void setHost($args); - * @method void setPort($args); - * @method void setCharset($args); - * @method void setOptions($args); - * @method void setIsFile($args); - * @method void setToMssql($args); - * @method void setPath($args); - * - * @method string getDriver(); - * @method string getDsn(); - * @method string getUser(); - * @method string getPassword() - * @method string getName(); - * @method string getHost(); - * @method string getPort(); - * @method string getCharset(); - * @method string getOptions(); - * @method bool getIsFile(); - * @method bool getToMssql(); - * @method string getPath(); - */ class Config extends ConfigAbstract implements ConfigInterface { public function __construct(string $driver = '', array $arguments = null) diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index c0632340..eec3acd1 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -450,7 +450,7 @@ public function query(string $query, bool $use_prepare = false) if ($this->processQuery($query, $param) === false) { if ($this->isTransactional) - throw new \PDOException($this->getLast_Error()); + throw new \PDOException($this->getLastError()); return false; } diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 8449fbe3..71f5aeb7 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -312,7 +312,7 @@ public function query(string $query, bool $use_prepare = false) if ($this->processQueryResult($query) === false) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->getLastError()); return false; } diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index 3ef53240..f36ac7f6 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -147,7 +147,7 @@ public function query_prepared(string $query, array $param = null) $stmt = $this->dbh->prepare($query); if (!$stmt instanceof \SQLite3Stmt) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->getLastError()); return false; } @@ -289,7 +289,7 @@ public function query(string $query, bool $use_prepare = false) if ($this->processQueryResult($query) === false) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->getLastError()); return false; } diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index b9b9ed9d..aca7a533 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -314,7 +314,7 @@ public function query(string $query, bool $use_prepare = false) if ($this->processQueryResult($query) === false) { if ($this->isTransactional) - throw new \Exception($this->getLast_Error()); + throw new \Exception($this->getLastError()); return false; } diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 50ed4b2c..857b26e6 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -9,6 +9,7 @@ use ezsql\Database; use ezsql\ezQueryInterface; use ezsql\DatabaseInterface; +use ezsql\ezsqlModelInterface; if (!\function_exists('ezFunctions')) { /** @@ -527,15 +528,104 @@ function cleanInput($string) } /** - * Returns an SQL string or result set, given the - * - table, column fields, conditions or conditional array. + * Preforms a `select` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * @param mixed $columns fields, string or array + * @param mixed ...$conditions - of the following parameters: + * + * @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ) + * - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()` + * - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)` + * @param $whereCondition, - `where` clause ( comparison(x, y, and) ) + * @param $groupBy, - `groupBy` clause + * @param $having, - `having` clause ( comparison(x, y, and) ) + * @param $orderby, - `orderby` clause for the query + * @param $limit, - `limit` clause the number of records + * @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed|object result set - see docs for more details, or false for error + */ + function selecting($columns = '*', ...$conditions) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->selecting($columns, ...$conditions) + : false; + } + + /** + * Preforms a `insert` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaped) + * @return int|bool bool/id of inserted record, or false for error + */ + function inserting(array $keyValue) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->inserting($keyValue) + : false; + } + + /** + * Set table `name` and `prefix` for global usage on calls to database **method/function** *names* ending with `ing`. + * + * @param string $name + * @param string $prefix + */ + function table_setup(string $name = '', string $prefix = '') + { + $ezQuery = getInstance(); + if (!$ezQuery instanceof ezsqlModelInterface) + return false; + + $ezQuery->tableSetup($name, $prefix); + } + + /** + * Set table `name` to use on calls to database **method/function** *names* ending with `ing`. + * + * @param string $append + */ + function set_table(string $name = '') + { + $ezQuery = getInstance(); + if (!$ezQuery instanceof ezsqlModelInterface) + return false; + + $ezQuery->setTable($name); + } + + /** + * Add a `prefix` to **append** to `table` name on calls to database **method/function** *names* ending with `ing`. + * + * @param string $append + */ + function set_prefix(string $append = '') + { + $ezQuery = getInstance(); + if (!$ezQuery instanceof ezsqlModelInterface) + return false; + + $ezQuery->setPrefix($append); + } + + /** + * Returns an `SQL string` or `result` set, given the + * - database table, column fields, conditions or conditional array. * * In the following format: - * ```js + * ```php * select( * table, * columns, - * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -546,24 +636,26 @@ function cleanInput($string) *); * ``` * @param $table, - database table to access - * @param $columnFields, - table columns, string or array + * @param $columns, - table columns, string or array * @param mixed ...$conditions - of the following parameters: * - * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) - * @param $whereKey, - where clause ( comparison(x, y, and) ) - * @param $groupBy, - grouping over clause the results - * @param $having, - having clause ( comparison(x, y, and) ) - * @param $orderby, - ordering by clause for the query - * @param $limit, - limit clause the number of records - * @param $union/$unionAll - union clause combine the result sets and removes duplicate rows/does not remove - * - * @return mixed result set - see docs for more details, or false for error + * @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ) + * - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()` + * - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)` + * @param $whereCondition, - `where` clause ( comparison(x, y, and) ) + * @param $groupBy, - `groupBy` over clause the results + * @param $having, - `having` clause ( comparison(x, y, and) ) + * @param $orderby, - `orderby` clause for the query + * @param $limit, - `limit` clause the number of records + * @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed|object result set - see docs for more details, or false for error */ - function select($table = '', $columns = '*', ...$args) + function select($table = '', $columns = '*', ...$conditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->select($table, $columns, ...$args) + ? $ezQuery->select($table, $columns, ...$conditions) : false; } @@ -572,49 +664,51 @@ function select($table = '', $columns = '*', ...$args) * @param $newTable, - new database table to be created * @param $fromColumns - the columns from old database table * @param $oldTable - old database table - * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra) ` * - * @return mixed bool/result - false for error + * @return mixed|object bool/result - false for error */ - function select_into($table, $columns = '*', $old = null, ...$args) + function select_into($newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->select_into($table, $columns, $old, ...$args) + ? $ezQuery->select_into($newTable, $fromColumns, $oldTable, ...$fromWhereConditions) : false; } /** - * Does an insert into select statement by calling insert method helper then selecting method + * Does an `insert into select` statement by calling insert method helper then `select` method * @param $toTable, - database table to insert table into * @param $toColumns - the receiving columns from other table columns, leave blank for all or array of column fields - * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * @param $fromTable, - from database table to use + * @param $fromColumns - the columns from old database table + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` * * @return mixed bool/id of inserted record, or false for error */ - function insert_select($totable = '', $columns = '*', $fromTable = null, $from = '*', ...$args) + function insert_select($totable = '', $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$whereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->insert_select($totable, $columns, $fromTable, $from, ...$args) + ? $ezQuery->insert_select($totable, $toColumns, $fromTable, $fromColumns, ...$whereConditions) : false; } /** - * Does an create select statement by calling selecting method + * Does an `create select` statement by calling `select` method * * @param $newTable, - new database table to be created * @param $fromColumns - the columns from old database table * @param $oldTable - old database table - * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) + * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` * * @return mixed bool/result - false for error */ - function create_select($table, $from, $old = null, ...$args) + function create_select($newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->create_select($table, $from, $old, ...$args) + ? $ezQuery->create_select($newTable, $fromColumns, $oldTable, ...$fromWhereConditions) : false; } @@ -627,7 +721,7 @@ function create_select($table, $from, $old = null, ...$args) * example: * `where( eq(key, value ), like('key', '_%?');` * - * @param array $whereConditions - In the following format: + * @param array $conditions - In the following format: *```js * eq('key/Field/Column', $value, _AND), // combine next expression * neq('key/Field/Column', $value, _OR), // will combine next expression if @@ -647,16 +741,16 @@ function create_select($table, $from, $old = null, ...$args) *``` * @return mixed bool/string - WHERE sql statement, or false on error */ - function where(...$whereConditions) + function where(...$conditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->where(...$whereConditions) + ? $ezQuery->where(...$conditions) : false; } /** - * Adds WHERE grouping to the conditions + * Adds WHERE `grouping` to the conditions * * format: * `grouping( comparison(x, y, and) )` @@ -664,7 +758,7 @@ function where(...$whereConditions) * example: * `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );` * - * @param array $whereConditions - In the following format: + * @param array $conditions - In the following format: *```js * eq('key/Field/Column', $value, _AND), // combine next expression * neq('key/Field/Column', $value, _OR), // will combine next expression again @@ -680,11 +774,11 @@ function where(...$whereConditions) *``` * @return array modified conditions */ - function grouping(...$args) + function grouping(...$conditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->grouping(...$args) + ? $ezQuery->grouping(...$conditions) : false; } @@ -711,7 +805,7 @@ function groupBy($groupBy) } /** - * Specifies a restriction over the groups of the query. + * Specifies a `restriction` over the groups of the query. * * format * `having( array(x, =, y, and, extra) );` or @@ -721,23 +815,31 @@ function groupBy($groupBy) * `having( array(key, operator, value, combine, extra) );`or * `having( "key operator value combine extra" );` * - * @param array $having - * @param string $key, - table column - * @param string $operator, - set the operator condition, - * either '<','>', '=', '!=', '>=', '<=', '<>', 'in', - * 'like', 'between', 'not between', 'is null', 'is not null' - * @param mixed $value, - will be escaped - * @param string $combine, - combine additional where clauses with, - * either 'AND','OR', 'NOT', 'AND NOT' - * or carry over of @value in the case the @operator is 'between' or 'not between' - * @param string $extra - carry over of @combine in the case the operator is 'between' or 'not between' + * @param array $conditions - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return bool/string - HAVING SQL statement, or false on error */ - function having(...$args) + function having(...$conditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->having(...$args) + ? $ezQuery->having(...$conditions) : false; } @@ -899,12 +1001,11 @@ function fullJoin( * - table, column fields, conditions or conditional array. * * In the following format: - * ``` + * ```php * union( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -931,12 +1032,11 @@ function union($table = '', $columnFields = '*', ...$conditions) * - table, column fields, conditions or conditional array. * * In the following format: - * ``` + * ```php * unionAll( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -946,7 +1046,7 @@ function union($table = '', $columnFields = '*', ...$conditions) * ``` * @param $table, - database table to access * @param $columnFields, - table columns, string or array - * @param mixed $conditions - same as selecting method. + * @param mixed $conditions - same as `select` method. * * @return bool|string - false for error */ @@ -991,9 +1091,9 @@ function limit($numberOf, $offset = null) } /** - * Does an insert query with an array + * Does an `insert` query with an array * @param $table, - database table to access - * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @param $keyValue - table fields, assoc array with key = value (doesn't need escaping) * @return mixed bool/id of inserted record, or false for error */ function insert($table = '', $keyValue = null) @@ -1005,37 +1105,74 @@ function insert($table = '', $keyValue = null) } /** - * Does an update query with an array, by conditional operator array + * Does an `update` query with an array, by conditional operator array * @param $table, - database table to access - * @param $keyAndValue, - table fields, assoc array with key = value (doesn't need escaped) - * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) - * + * @param $keyValue, - table fields, assoc array with key = value (doesn't need escaping) + * @param $whereConditions, - where clause `eq('x', $y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/results - false for error */ - function update($table = '', $keyValue = null, ...$args) + function update($table = '', $keyValue = null, ...$whereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->update($table, $keyValue, ...$args) + ? $ezQuery->update($table, $keyValue, ...$whereConditions) : false; } /** - * Does the delete query with an array + * Does an `delete` query with an array + * @param $table, - database table to access + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/results - false for error */ - function deleting($table = '', ...$args) + function delete($table = null, ...$whereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->delete($table, ...$args) + ? $ezQuery->delete($table, ...$whereConditions) : false; } /** - * Does an replace query with an array + * Does an `replace` query with an array * @param $table, - database table to access - * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @param $keyValue - table fields, assoc array with key = value (doesn't need escaping) * @return mixed bool/id of replaced record, or false for error */ function replace($table = '', $keyValue = null) diff --git a/lib/ezQuery.php b/lib/ezQuery.php index fe20ce5a..b3524c1c 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -11,8 +11,27 @@ class ezQuery implements ezQueryInterface protected $select_result = true; protected $prepareActive = false; protected $preparedValues = array(); + + /** + * ID generated from the AUTO_INCREMENT of the previous INSERT operation (if any) + * @var int + */ protected $insertId = null; + /** + * The table `name` to use on calls to `selecting` method. + * + * @var string + */ + protected $table = ''; + + /** + * A `prefix` to append to `table` on calls to `selecting` method. + * + * @var string + */ + protected $prefix = ''; + private $fromTable = null; private $isWhere = true; private $isInto = false; @@ -149,7 +168,7 @@ public function prepareOff() } /** - * Convert array to string, and attach '`, `' for separation, if none is provided. + * Convert array to string, and attach '`,`' for separation, if none is provided. * * @return string */ @@ -177,10 +196,10 @@ public function groupBy($groupBy) return 'GROUP BY ' . $columns; } - public function having(...$having) + public function having(...$conditions) { $this->isWhere = false; - return $this->where(...$having); + return $this->where(...$conditions); } public function innerJoin( @@ -477,10 +496,10 @@ public function grouping(...$whereConditions) return $whereConditions; } - public function where(...$whereConditions) + public function where(...$conditions) { - if (empty($whereConditions)) + if (empty($conditions)) return false; $whereOrHaving = ($this->isWhere) ? 'WHERE' : 'HAVING'; @@ -488,10 +507,10 @@ public function where(...$whereConditions) $this->combineWith = ''; - if (\is_string($whereConditions[0]) && \strpos($whereConditions[0], $whereOrHaving) !== false) - return $whereConditions[0]; + if (\is_string($conditions[0]) && \strpos($conditions[0], $whereOrHaving) !== false) + return $conditions[0]; - list($operator, $whereKeys, $whereValues, $combiner, $extra) = $this->retrieveConditions($whereConditions); + list($operator, $whereKeys, $whereValues, $combiner, $extra) = $this->retrieveConditions($conditions); if (empty($operator)) return false; @@ -522,6 +541,30 @@ public function where(...$whereConditions) return ($where != '1') ? " $whereOrHaving $where " : ' '; } + public function selecting($columns = '*', ...$conditions) + { + if (empty($this->table) || !\is_string($this->table)) + return $this->clearPrepare(); + + $table = (!empty($this->prefix) || \is_string($this->prefix)) + ? $this->prefix . $this->table + : $this->table; + + return $this->select($table, $columns, ...$conditions); + } + + public function inserting(array $keyValue) + { + if (empty($this->table) || !\is_string($this->table)) + return $this->clearPrepare(); + + $table = (!empty($this->prefix) || \is_string($this->prefix)) + ? $this->prefix . $this->table + : $this->table; + + return $this->insert($table, $keyValue); + } + public function select(string $table = null, $columnFields = '*', ...$conditions) { $getFromTable = $this->fromTable; @@ -631,7 +674,7 @@ public function unionAll(string $table = null, $columnFields = '*', ...$conditio return 'UNION ALL ' . $this->select_sql($table, $columnFields, ...$conditions); } - public function create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions) + public function create_select(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) { if (isset($oldTable)) $this->fromTable = $oldTable; @@ -639,7 +682,7 @@ public function create_select(string $newTable, $fromColumns, $oldTable = null, return $this->clearPrepare(); } - $newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$conditions); + $newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$fromWhereConditions); if (is_string($newTableFromTable)) return (($this->isPrepareOn()) && !empty($this->prepareValues())) ? $this->query($newTableFromTable, true) @@ -648,7 +691,7 @@ public function create_select(string $newTable, $fromColumns, $oldTable = null, return $this->clearPrepare(); } - public function select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions) + public function select_into(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions) { $this->isInto = true; if (isset($oldTable)) @@ -656,7 +699,7 @@ public function select_into(string $newTable, $fromColumns, $oldTable = null, .. else return $this->clearPrepare(); - $newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$conditions); + $newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$fromWhereConditions); if (is_string($newTableFromTable)) return (($this->isPrepareOn()) && !empty($this->prepareValues())) ? $this->query($newTableFromTable, true) @@ -665,15 +708,15 @@ public function select_into(string $newTable, $fromColumns, $oldTable = null, .. return $this->clearPrepare(); } - public function update(string $table = null, $keyAndValue, ...$whereConditions) + public function update(string $table = null, $keyValue, ...$whereConditions) { - if (!is_array($keyAndValue) || empty($table)) { + if (!is_array($keyValue) || empty($table)) { return $this->clearPrepare(); } $sql = "UPDATE $table SET "; - foreach ($keyAndValue as $key => $val) { + foreach ($keyValue as $key => $val) { if (\strtolower($val) == 'null') { $sql .= "$key = NULL, "; } elseif (\in_array(\strtolower($val), array('current_timestamp()', 'date()', 'now()'))) { @@ -721,9 +764,9 @@ public function delete(string $table = null, ...$whereConditions) * Helper does the actual insert or replace query with an array * @return mixed bool/results - false for error */ - private function _query_insert_replace($table = '', $keyAndValue = null, $type = '', $execute = true) + private function _query_insert_replace($table = '', $keyValue = null, $type = '', $execute = true) { - if ((!\is_array($keyAndValue) && ($execute)) || empty($table)) { + if ((!\is_array($keyValue) && ($execute)) || empty($table)) { return $this->clearPrepare(); } @@ -736,7 +779,7 @@ private function _query_insert_replace($table = '', $keyAndValue = null, $type = $index = ''; if ($execute) { - foreach ($keyAndValue as $key => $val) { + foreach ($keyValue as $key => $val) { $index .= "$key, "; if (\strtolower($val) == 'null') $value .= "NULL, "; @@ -763,9 +806,9 @@ private function _query_insert_replace($table = '', $keyAndValue = null, $type = return $this->clearPrepare(); } else { - if (\is_array($keyAndValue)) { - if (\array_keys($keyAndValue) === \range(0, \count($keyAndValue) - 1)) { - foreach ($keyAndValue as $key) { + if (\is_array($keyValue)) { + if (\array_keys($keyValue) === \range(0, \count($keyValue) - 1)) { + foreach ($keyValue as $key) { $index .= "$key, "; } $sql .= " (" . \rtrim($index, ', ') . ") "; @@ -778,14 +821,14 @@ private function _query_insert_replace($table = '', $keyAndValue = null, $type = } } - public function replace(string $table = null, $keyAndValue) + public function replace(string $table = null, $keyValue) { - return $this->_query_insert_replace($table, $keyAndValue, 'REPLACE'); + return $this->_query_insert_replace($table, $keyValue, 'REPLACE'); } - public function insert(string $table = null, $keyAndValue) + public function insert(string $table = null, $keyValue) { - return $this->_query_insert_replace($table, $keyAndValue, 'INSERT'); + return $this->_query_insert_replace($table, $keyValue, 'INSERT'); } public function insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions) @@ -802,11 +845,8 @@ public function insert_select(string $toTable = null, $toColumns = '*', $fromTab } // get_results call template - public function get_results( - string $query = null, - $output = \OBJECT, - bool $use_prepare = false - ) { + public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) + { return array(); } @@ -853,7 +893,7 @@ public function escape(string $str) /** * Creates an database schema from array * - column, datatype, value/options/key arguments. - * + * @param array ...$columnDataOptions * @return string|bool - SQL schema string, or false for error */ private function create_schema(array ...$columnDataOptions) @@ -972,7 +1012,7 @@ public function alter(string $table = null, ...$schemas) } /** - * Does an drop table query if table exists. + * Does an `drop` table query if table exists. * @param $table - database table to erase * * @return bool diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 38fa8f59..e3081524 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -51,7 +51,7 @@ public function prepareOff(); /** * Specifies a grouping over the results of the query. * - * selecting('table', + * select('table', * 'columns', * where( eq( 'columns', values, _AND ), like( 'columns', _d ) ), * groupBy( 'columns' ), @@ -65,7 +65,7 @@ public function prepareOff(); public function groupBy($groupBy); /** - * Specifies a restriction over the groups of the query. + * Specifies a `restriction` over the groups of the query. * * format * `having( array(x, =, y, and, extra) );` or @@ -75,19 +75,28 @@ public function groupBy($groupBy); * `having( array(key, operator, value, combine, extra) );`or * `having( "key operator value combine extra" );` * - * @param array $having - * @param string $key, - table column - * @param string $operator, - set the operator condition, - * either '<','>', '=', '!=', '>=', '<=', '<>', 'in', - * 'like', 'between', 'not between', 'is null', 'is not null' - * @param mixed $value, - will be escaped - * @param string $combine, - combine additional where clauses with, - * either 'AND','OR', 'NOT', 'AND NOT' - * or carry over of @value in the case the @operator is 'between' or 'not between' - * @param string $extra - carry over of @combine in the case the operator is 'between' or 'not between' + * @param array $conditions + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return bool/string - HAVING SQL statement, or false on error */ - public function having(...$having); + public function having(...$conditions); /** * Return all rows from multiple tables where the join condition is met. @@ -227,12 +236,11 @@ public function fullJoin( * - table, column fields, conditions or conditional array. * * In the following format: - * ``` + * ```php * union( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -242,7 +250,7 @@ public function fullJoin( * ``` * @param $table, - database table to access * @param $columnFields, - table columns, string or array - * @param mixed $conditions - same as selecting method. + * @param mixed $conditions - same as select method. * * @return bool|string - false for error */ @@ -253,12 +261,11 @@ public function union(string $table = null, $columnFields = '*', ...$conditions) * - table, column fields, conditions or conditional array. * * In the following format: - * ``` + * ```php * unionAll( * table, * columns, - * // innerJoin(), leftJoin(), rightJoin(), fullJoin() alias of - * joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -268,7 +275,7 @@ public function union(string $table = null, $columnFields = '*', ...$conditions) * ``` * @param $table, - database table to access * @param $columnFields, - table columns, string or array - * @param mixed $conditions - same as selecting method. + * @param mixed $conditions - same as select method. * * @return bool|string - false for error */ @@ -295,7 +302,7 @@ public function orderBy($orderBy, $order); public function limit($numberOf, $offset = null); /** - * Helper adds WHERE grouping to the conditions + * Adds WHERE `grouping` to the conditions * * format: * `grouping( comparison(x, y, and) )` @@ -322,7 +329,7 @@ public function limit($numberOf, $offset = null); public function grouping(...$whereConditions); /** - * Helper returns an WHERE sql clause string. + * Returns an `WHERE` **sql clause** string. * * format: * `where( comparison(x, y, and) )` @@ -350,19 +357,19 @@ public function grouping(...$whereConditions); *``` * @return mixed bool/string - WHERE SQL statement, or false on error */ - public function where(...$whereConditions); + public function where(...$conditions); /** - * Returns an SQL string or result set, given the - * - table, column fields, conditions or conditional array. + * Returns an `SQL string` or `result` set, given the + * - database table, column fields, conditions or conditional array. * * In the following format: - * ```js + * ```php * select( * table, * columns, - * (innerJoin(), leftJoin(), rightJoin(), fullJoin()), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), * where( eq( columns, values, _AND ), like( columns, _d ) ), * groupBy( columns ), * having( between( columns, values1, values2 ) ), @@ -376,79 +383,205 @@ public function where(...$whereConditions); * @param $columnFields, - table columns, string or array * @param mixed ...$conditions - of the following parameters: * - * @param $joins, - join clause (type, left table, right table, left column, right column, condition = EQ) - * @param $whereKey, - where clause ( comparison(x, y, and) ) - * @param $groupBy, - grouping over clause the results - * @param $having, - having clause ( comparison(x, y, and) ) - * @param $orderby, - ordering by clause for the query - * @param $limit, - limit clause the number of records - * @param $union/$unionAll - union clause combine the result sets and removes duplicate rows/does not remove - * - * @return mixed result set - see docs for more details, or false for error + * @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ) + * - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()` + * - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)` + * @param $whereConditions, - `where` clause ( comparison(x, y, and) ) + * @param $groupBy, - `groupBy` clause + * @param $having, - `having` clause ( comparison(x, y, and) ) + * @param $orderby, - `orderby` clause for the query + * @param $limit, - `limit` clause the number of records + * @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed|object result set - see docs for more details, or false for error */ public function select(string $table = null, $columnFields = '*', ...$conditions); /** - * Does an create select statement by calling selecting method + * Preforms a `select` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * @param mixed $columns fields, string or array + * @param mixed ...$conditions - of the following parameters: + * + * @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ) + * - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()` + * - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)` + * @param $whereConditions, - `where` clause ( comparison(x, y, and) ) + * @param $groupBy, - `groupBy` clause + * @param $having, - `having` clause ( comparison(x, y, and) ) + * @param $orderby, - `orderby` clause for the query + * @param $limit, - `limit` clause the number of records + * @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove + * + * @return mixed|object result set - see docs for more details, or false for error + */ + public function selecting($columns = '*', ...$conditions); + + /** + * Preforms a `insert` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaped) + * @return int|bool bool/id of inserted record, or false for error + */ + function inserting(array $keyValue); + + /** + * Does an `create select` statement by calling `select` method * * @param $newTable, - new database table to be created * @param $fromColumns - the columns from old database table * @param $oldTable - old database table - * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) - * + * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/result - false for error */ - public function create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions); + public function create_select(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions); /** - * Does an select into statement by calling selecting method + * Does an `select into` statement by calling `select` method * @param $newTable, - new database table to be created * @param $fromColumns - the columns from old database table * @param $oldTable - old database table - * @param $fromWhere, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) - * + * @param $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/result - false for error */ - public function select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions); + public function select_into(string $newTable, $fromColumns = '*', $oldTable = null, ...$fromWhereConditions); /** - * Does an update query with an array, by conditional operator array + * Does an `update` query with an array, by conditional operator array * @param $table, - database table to access - * @param $keyAndValue, - table fields, assoc array with key = value (doesn't need escaped) - * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) - * + * @param $keyValue, - table fields, assoc array with key = value (doesn't need escaped) + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/results - false for error */ - public function update(string $table = null, $keyAndValue, ...$whereConditions); + public function update(string $table = null, $keyValue, ...$whereConditions); /** - * Helper does the actual delete query with an array + * Does an `delete` query with an array + * @param $table, - database table to access + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/results - false for error */ public function delete(string $table = null, ...$whereConditions); /** - * Does an replace query with an array + * Does an `replace` query with an array * @param $table, - database table to access - * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) * @return mixed bool/id of replaced record, or false for error */ - public function replace(string $table = null, $keyAndValue); + public function replace(string $table = null, $keyValue); /** - * Does an insert query with an array + * Does an `insert` query with an array * @param $table, - database table to access - * @param $keyAndValue - table fields, assoc array with key = value (doesn't need escaped) + * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) * @return mixed bool/id of inserted record, or false for error */ - public function insert(string $table = null, $keyAndValue); + public function insert(string $table = null, $keyValue); /** - * Does an insert into select statement by calling insert method helper then selecting method + * Does an `insert into select` statement by calling insert method helper then `select` method * @param $toTable, - database table to insert table into * @param $toColumns - the receiving columns from other table columns, leave blank for all or array of column fields - * @param $WhereKey, - where clause ( array(x, =, y, and, extra) ) or ( "x = y and extra" ) - * + * @param $fromTable, - from database table to use + * @param $fromColumns - the columns from old database table + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` * @return mixed bool/id of inserted record, or false for error */ public function insert_select( @@ -456,7 +589,7 @@ public function insert_select( $toColumns = '*', $fromTable = null, $fromColumns = '*', - ...$conditions + ...$whereConditions ); /** diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 99ba70cf..1493821c 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -9,6 +9,76 @@ /** * Core class containing common functions to manipulate query result * sets once returned + * + * @method set/get{property} - a property that needs to be accessed + * + * @method void setDebugAll($args); + * @method void setTrace($args); + * @method void setDebugCalled($args); + * @method void setVarDumpCalled($args); + * @method void setShowErrors($args); + * @method void setNumQueries($args); + * @method void setConnQueries($args); + * @method void setCapturedErrors($args); + * @method void setCacheDir($args); + * @method void setUseDiskCache($args); + * @method void setCacheTimeout($args); + * @method void setCacheQueries($args); + * @method void setCacheInserts($args); + * @method void setNumRows($args); + * @method void setDbConnectTime($args); + * @method void setSqlLogFile($args); + * @method void setProfileTimes($args); + * @method void setInsertId($args); + * @method void setLastQuery($args); + * @method void setLastError($args); + * @method void setColInfo($args); + * @method void setTimers($args); + * @method void setTotalQueryTime($args); + * @method void setTraceLog($args); + * @method void setUseTraceLog($args); + * @method void setDoProfile($args); + * @method void setLastResult($args); + * @method void setFromDiskCache($args); + * @method void setDebugEchoIsOn($args); + * @method void setFuncCall($args); + * @method void setAllFuncCalls($args); + * @method void setTable($name); + * @method void setPrefix($append); + * + * @method string getDebugAll(); + * @method string getTrace(); + * @method string getDebugCalled(); + * @method string getVarDumpCalled(); + * @method string getShowErrors(); + * @method string getNumQueries(); + * @method string getConnQueries(); + * @method string getCapturedErrors(); + * @method string getCacheDir(); + * @method string getUseDiskCache(); + * @method string getCacheTimeout(); + * @method string getCacheQueries(); + * @method string getCacheInserts(); + * @method string getNumRows(); + * @method string getDbConnectTime(); + * @method string getSqlLogFile(); + * @method string getProfileTimes(); + * @method string getInsertId(); + * @method string getLastQuery(); + * @method string getLastError(); + * @method string getColInfo(); + * @method string getTimers(); + * @method string getTotalQueryTime(); + * @method string getTraceLog(); + * @method string getUseTraceLog(); + * @method string getDoProfile(); + * @method string getLastResult(); + * @method string getFromDiskCache(); + * @method string getDebugEchoIsOn(); + * @method string getFuncCall(); + * @method string getAllFuncCalls(); + * @method string getTable(); + * @method string getPrefix(); */ class ezsqlModel extends ezQuery implements ezsqlModelInterface { @@ -106,6 +176,20 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface */ protected $lastQuery = null; + /** + * The table `name` to use on calls to `selecting` method. + * + * @var string + */ + protected $table = ''; + + /** + * A `prefix` to append to `table` name on calls to `selecting` method. + * + * @var string + */ + protected $prefix = ''; + /** * Use to keep track of last error * @var string @@ -178,70 +262,6 @@ public function __construct() * Magic methods for Calling Non-Existent Functions, handling Getters and Setters. * @method set/get{property} - a property that needs to be accessed * - * @method void setDebugAll($args); - * @method void setTrace($args); - * @method void setDebugCalled($args); - * @method void setVarDumpCalled($args); - * @method void setShowErrors($args); - * @method void setNumQueries($args); - * @method void setConnQueries($args); - * @method void setCapturedErrors($args); - * @method void setCacheDir($args); - * @method void setUseDiskCache($args); - * @method void setCacheTimeout($args); - * @method void setCacheQueries($args); - * @method void setCacheInserts($args); - * @method void setNumRows($args); - * @method void setDbConnectTime($args); - * @method void setSqlLogFile($args); - * @method void setProfileTimes($args); - * @method void setInsertId($args); - * @method void setLastQuery($args); - * @method void setLastError($args); - * @method void setColInfo($args); - * @method void setTimers($args); - * @method void setTotalQueryTime($args); - * @method void setTraceLog($args); - * @method void setUseTraceLog($args); - * @method void setDoProfile($args); - * @method void setLastResult($args); - * @method void setFromDiskCache($args); - * @method void setDebugEchoIsOn($args); - * @method void setFuncCall($args); - * @method void setAllFuncCalls($args); - * - * @method string getDebugAll(); - * @method string getTrace(); - * @method string getDebugCalled(); - * @method string getVarDumpCalled(); - * @method string getShowErrors(); - * @method string getNumQueries(); - * @method string getConnQueries(); - * @method string getCapturedErrors(); - * @method string getCacheDir(); - * @method string getUseDiskCache(); - * @method string getCacheTimeout(); - * @method string getCacheQueries(); - * @method string getCacheInserts(); - * @method string getNumRows(); - * @method string getDbConnectTime(); - * @method string getSqlLogFile(); - * @method string getProfileTimes(); - * @method string getInsertId(); - * @method string getLastQuery(); - * @method string getLastError(); - * @method string getColInfo(); - * @method string getTimers(); - * @method string getTotalQueryTime(); - * @method string getTraceLog(); - * @method string getUseTraceLog(); - * @method string getDoProfile(); - * @method string getLastResult(); - * @method string getFromDiskCache(); - * @method string getDebugEchoIsOn(); - * @method string getFuncCall(); - * @method string getAllFuncCalls(); - * * @property-read function * @property-write args * @@ -729,33 +749,24 @@ public function secureReset() $this->secureOptions = null; } - /** - * Returns `true` if the database connection is established. - * - * @return bool - */ public function isConnected() { return $this->_connected; } // isConnected - /** - * Returns the `number` of affected rows of a query. - * - * @return int - */ public function affectedRows() { return $this->_affectedRows; } // affectedRows - /** - * Returns the last query `result`. - * - * @return object - */ public function queryResult() { return $this->lastResult; } + + public function tableSetup(string $name = '', string $prefix = '') + { + $this->table = $name; + $this->prefix = $prefix; + } } // ezsqlModel diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 3e85c6f9..259564a3 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -2,6 +2,77 @@ namespace ezsql; +/** + * @method set/get{property} - a property that needs to be accessed + * + * @method void setDebugAll($args); + * @method void setTrace($args); + * @method void setDebugCalled($args); + * @method void setVarDumpCalled($args); + * @method void setShowErrors($args); + * @method void setNumQueries($args); + * @method void setConnQueries($args); + * @method void setCapturedErrors($args); + * @method void setCacheDir($args); + * @method void setUseDiskCache($args); + * @method void setCacheTimeout($args); + * @method void setCacheQueries($args); + * @method void setCacheInserts($args); + * @method void setNumRows($args); + * @method void setDbConnectTime($args); + * @method void setSqlLogFile($args); + * @method void setProfileTimes($args); + * @method void setInsertId($args); + * @method void setLastQuery($args); + * @method void setLastError($args); + * @method void setColInfo($args); + * @method void setTimers($args); + * @method void setTotalQueryTime($args); + * @method void setTraceLog($args); + * @method void setUseTraceLog($args); + * @method void setDoProfile($args); + * @method void setLastResult($args); + * @method void setFromDiskCache($args); + * @method void setDebugEchoIsOn($args); + * @method void setFuncCall($args); + * @method void setAllFuncCalls($args); + * @method void setTable($name); + * @method void setPrefix($append); + * + * @method string getDebugAll(); + * @method string getTrace(); + * @method string getDebugCalled(); + * @method string getVarDumpCalled(); + * @method string getShowErrors(); + * @method string getNumQueries(); + * @method string getConnQueries(); + * @method string getCapturedErrors(); + * @method string getCacheDir(); + * @method string getUseDiskCache(); + * @method string getCacheTimeout(); + * @method string getCacheQueries(); + * @method string getCacheInserts(); + * @method string getNumRows(); + * @method string getDbConnectTime(); + * @method string getSqlLogFile(); + * @method string getProfileTimes(); + * @method string getInsertId(); + * @method string getLastQuery(); + * @method string getLastError(); + * @method string getColInfo(); + * @method string getTimers(); + * @method string getTotalQueryTime(); + * @method string getTraceLog(); + * @method string getUseTraceLog(); + * @method string getDoProfile(); + * @method string getLastResult(); + * @method string getFromDiskCache(); + * @method string getDebugEchoIsOn(); + * @method string getFuncCall(); + * @method string getAllFuncCalls(); + * @method string getTable(); + * @method string getPrefix(); + */ interface ezsqlModelInterface { /** @@ -234,23 +305,32 @@ public function timer_update_global($timer_name); public function count($all = true, $increase = false); /** - * Returns, whether a database connection is established, or not + * Returns `true` if the database connection is established. * - * @return boolean + * @return bool */ public function isConnected(); /** - * Returns the affected rows of a query + * Returns the `number` of affected rows of a query. * * @return int */ public function affectedRows(); /** - * Returns the last query result + * Returns the last query `result`. * - * @return array + * @return object */ public function queryResult(); + + /** + * Setup table `name` and `prefix` for global usage on calls to database **method/function** *names* ending with `ing`. + * + * @param string $name + * @param string $prefix + * @return void + */ + public function tableSetup(string $name = '', string $prefix = ''); } diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index d853945c..ebb42ecb 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -41,8 +41,13 @@ orderBy, insert, update, - deleting, - replace + delete, + replace, + selecting, + inserting, + table_setup, + set_table, + set_prefix }; class ezFunctionsTest extends EZTestCase @@ -244,9 +249,34 @@ public function testUpdate() $this->assertFalse(update('field', 'data', 'data2')); } - public function testDeleting() + public function testDelete() { - $this->assertFalse(deleting('field', 'data', 'data2')); + $this->assertFalse(delete('field', 'data', 'data2')); + } + + public function testInserting() + { + $this->assertFalse(inserting([])); + } + + public function testTable_Setup() + { + $this->assertFalse(table_setup()); + } + + public function testSelecting() + { + $this->assertFalse(selecting()); + } + + public function testSet_Table() + { + $this->assertFalse(set_table()); + } + + public function testSet_Prefix() + { + $this->assertFalse(set_prefix()); } public function testReplace() diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index de87fa30..8b07fbd4 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -12,31 +12,13 @@ column, primary, eq, - neq, - ne, - lt, - lte, - gt, - gte, - isNotNull, like, - in, - notLike, - notIn, between, - notBetween, select, - select_into, - insert_select, - create_select, - where, - groupBy, - having, - orderBy, - insert, - update, - deleting, - replace + selecting, + inserting, + table_setup, + where }; class mysqliTest extends EZTestCase @@ -384,6 +366,46 @@ public function testSelect() } } + public function testSelectingInserting() + { + $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); + $this->object->dbSelect(self::TEST_DB_NAME); + $this->object->create( + 'unit_test', + column('id', INTR, 11, PRIMARY), + column('test_key', VARCHAR, 50) + ); + + table_setup('unit_test'); + $this->assertEquals(1, inserting(array('id' => 1, 'test_key' => 'testing 1'))); + inserting(array('id' => 2, 'test_key' => 'testing 2')); + inserting(array('id' => 3, 'test_key' => 'testing 3')); + + $result = selecting(); + + $i = 1; + foreach ($result as $row) { + $this->assertEquals($i, $row->id); + $this->assertEquals('testing ' . $i, $row->test_key); + ++$i; + } + + $result = $this->object->selecting('id', eq('test_key', 'testing 2')); + foreach ($result as $row) { + $this->assertEquals(2, $row->id); + } + + $result = selecting('test_key', ['id', '=', 3]); + foreach ($result as $row) { + $this->assertEquals('testing 3', $row->test_key); + } + + $result = selecting(array('test_key'), "id = 1"); + foreach ($result as $row) { + $this->assertEquals('testing 1', $row->test_key); + } + } + public function testBeginTransactionCommit() { $this->object->connect(); From ede99e1e5db0469077164df0276b5879f6ba641c Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 15 Feb 2021 16:14:48 -0500 Subject: [PATCH 144/148] BC, start removing global functions where `table` name passed in, use the ones with preset table names --- lib/ezFunctions.php | 259 ++++++++++++++-------------- lib/ezQuery.php | 79 ++++++--- lib/ezQueryInterface.php | 104 ++++++++++- tests/ezFunctionsTest.php | 24 +-- tests/mysqli/mysqliTest.php | 26 ++- tests/pdo/pdo_mysqlTest.php | 9 +- tests/postgresql/postgresqlTest.php | 45 ++++- 7 files changed, 359 insertions(+), 187 deletions(-) diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 857b26e6..77e3f371 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -530,8 +530,26 @@ function cleanInput($string) /** * Preforms a `select` method call on a already preset `table name`, and optional `prefix` * - * This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + + * Returns an `result` set, given the + * - column fields, conditions or conditional array. + * + * In the following format: + * ```php + * selecting( + * columns, + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ), + * union(table, columnFields, conditions), // Returns an select SQL string with `UNION` + * unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL` + *); + * ``` * * @param mixed $columns fields, string or array * @param mixed ...$conditions - of the following parameters: @@ -559,10 +577,11 @@ function selecting($columns = '*', ...$conditions) /** * Preforms a `insert` method call on a already preset `table name`, and optional `prefix` * - * This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * - * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaped) + * Does an `insert` query with an array + * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping) * @return int|bool bool/id of inserted record, or false for error */ function inserting(array $keyValue) @@ -574,7 +593,114 @@ function inserting(array $keyValue) } /** - * Set table `name` and `prefix` for global usage on calls to database **method/function** *names* ending with `ing`. + * Preforms a `update` method call on a already preset `table name`, and optional `prefix` + * + * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `update` query with an array, by conditional operator array + * @param array $keyValue, - table fields, assoc array with key = value (doesn't need escaped) + * @param mixed ...$whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/results - false for error + */ + function updating(array $keyValue, ...$whereConditions) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->updating($keyValue, ...$whereConditions) + : false; + } + + /** + * Preforms a `create` method call on a already preset `table name`, and optional `prefix` + * + * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Creates an database table with columns, by either: + *```js + * - array( column, datatype, ...value/options arguments ) // calls create_schema() + * - column( column, datatype, ...value/options arguments ) // returns string + * - primary( primary_key_label, ...primaryKeys) // returns string + * - foreign( foreign_key_label, ...foreignKeys) // returns string + * - unique( unique_key_label, ...uniqueKeys) // returns string + *``` + * @param array ...$schemas An array of: + * + * - @param string `$column | CONSTRAINT,` - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY + * - @param string `$type | $constraintName,` - data type for column/primary | foreign constraint name + * - @param mixed `$size | ...$primaryForeignKeys,` + * - @param mixed `$value,` - column should be NULL or NOT NULL. If omitted, assumes NULL + * - @param mixed `$default` - Optional. It is the value to assign to the column + * + * @return mixed results of query() call + */ + function creating(...$schemas) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->creating(...$schemas) + : false; + } + + /** + * Preforms a `delete` method call on a already preset `table name`, and optional `prefix` + * + * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `delete` query with an array + * @param $table, - database table to access + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/results - false for error + */ + function deleting(...$whereConditions) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->deleting(...$whereConditions) + : false; + } + + /** + * Set table `name` and `prefix` for global usage on calls to database + * **method/function** *names* ending with `ing`. * * @param string $name * @param string $prefix @@ -603,7 +729,8 @@ function set_table(string $name = '') } /** - * Add a `prefix` to **append** to `table` name on calls to database **method/function** *names* ending with `ing`. + * Add a `prefix` to **append** to `table` name on calls to database + * **method/function** *names* ending with `ing`. * * @param string $append */ @@ -616,49 +743,6 @@ function set_prefix(string $append = '') $ezQuery->setPrefix($append); } - /** - * Returns an `SQL string` or `result` set, given the - * - database table, column fields, conditions or conditional array. - * - * In the following format: - * ```php - * select( - * table, - * columns, - * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), - * where( eq( columns, values, _AND ), like( columns, _d ) ), - * groupBy( columns ), - * having( between( columns, values1, values2 ) ), - * orderBy( columns, desc ), - * limit( numberOfRecords, offset ), - * union(table, columnFields, conditions), // Returns an select SQL string with `UNION` - * unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL` - *); - * ``` - * @param $table, - database table to access - * @param $columns, - table columns, string or array - * @param mixed ...$conditions - of the following parameters: - * - * @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ) - * - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()` - * - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)` - * @param $whereCondition, - `where` clause ( comparison(x, y, and) ) - * @param $groupBy, - `groupBy` over clause the results - * @param $having, - `having` clause ( comparison(x, y, and) ) - * @param $orderby, - `orderby` clause for the query - * @param $limit, - `limit` clause the number of records - * @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove - * - * @return mixed|object result set - see docs for more details, or false for error - */ - function select($table = '', $columns = '*', ...$conditions) - { - $ezQuery = getInstance(); - return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->select($table, $columns, ...$conditions) - : false; - } - /** * Does an select into statement by calling selecting method * @param $newTable, - new database table to be created @@ -1090,85 +1174,6 @@ function limit($numberOf, $offset = null) : false; } - /** - * Does an `insert` query with an array - * @param $table, - database table to access - * @param $keyValue - table fields, assoc array with key = value (doesn't need escaping) - * @return mixed bool/id of inserted record, or false for error - */ - function insert($table = '', $keyValue = null) - { - $ezQuery = getInstance(); - return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->insert($table, $keyValue) - : false; - } - - /** - * Does an `update` query with an array, by conditional operator array - * @param $table, - database table to access - * @param $keyValue, - table fields, assoc array with key = value (doesn't need escaping) - * @param $whereConditions, - where clause `eq('x', $y, _AND), another clause - same as array(x, =, y, and, extra)` - * - In the following format: - *```js - * eq('key/Field/Column', $value, _AND), // combine next expression - * neq('key/Field/Column', $value, _OR), // will combine next expression if - * ne('key/Field/Column', $value), // the default is _AND so will combine next expression - * lt('key/Field/Column', $value) - * lte('key/Field/Column', $value) - * gt('key/Field/Column', $value) - * gte('key/Field/Column', $value) - * isNull('key/Field/Column') - * isNotNull('key/Field/Column') - * like('key/Field/Column', '_%') - * notLike('key/Field/Column', '_%') - * in('key/Field/Column', $values) - * notIn('key/Field/Column', $values) - * between('key/Field/Column', $value, $value2) - * notBetween('key/Field/Column', $value, $value2) - *``` - * @return mixed bool/results - false for error - */ - function update($table = '', $keyValue = null, ...$whereConditions) - { - $ezQuery = getInstance(); - return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->update($table, $keyValue, ...$whereConditions) - : false; - } - - /** - * Does an `delete` query with an array - * @param $table, - database table to access - * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` - * - In the following format: - *```js - * eq('key/Field/Column', $value, _AND), // combine next expression - * neq('key/Field/Column', $value, _OR), // will combine next expression if - * ne('key/Field/Column', $value), // the default is _AND so will combine next expression - * lt('key/Field/Column', $value) - * lte('key/Field/Column', $value) - * gt('key/Field/Column', $value) - * gte('key/Field/Column', $value) - * isNull('key/Field/Column') - * isNotNull('key/Field/Column') - * like('key/Field/Column', '_%') - * notLike('key/Field/Column', '_%') - * in('key/Field/Column', $values) - * notIn('key/Field/Column', $values) - * between('key/Field/Column', $value, $value2) - * notBetween('key/Field/Column', $value, $value2) - *``` - * @return mixed bool/results - false for error - */ - function delete($table = null, ...$whereConditions) - { - $ezQuery = getInstance(); - return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->delete($table, ...$whereConditions) - : false; - } - /** * Does an `replace` query with an array * @param $table, - database table to access diff --git a/lib/ezQuery.php b/lib/ezQuery.php index b3524c1c..a365444e 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -541,30 +541,6 @@ public function where(...$conditions) return ($where != '1') ? " $whereOrHaving $where " : ' '; } - public function selecting($columns = '*', ...$conditions) - { - if (empty($this->table) || !\is_string($this->table)) - return $this->clearPrepare(); - - $table = (!empty($this->prefix) || \is_string($this->prefix)) - ? $this->prefix . $this->table - : $this->table; - - return $this->select($table, $columns, ...$conditions); - } - - public function inserting(array $keyValue) - { - if (empty($this->table) || !\is_string($this->table)) - return $this->clearPrepare(); - - $table = (!empty($this->prefix) || \is_string($this->prefix)) - ? $this->prefix . $this->table - : $this->table; - - return $this->insert($table, $keyValue); - } - public function select(string $table = null, $columnFields = '*', ...$conditions) { $getFromTable = $this->fromTable; @@ -710,7 +686,7 @@ public function select_into(string $newTable, $fromColumns = '*', $oldTable = nu public function update(string $table = null, $keyValue, ...$whereConditions) { - if (!is_array($keyValue) || empty($table)) { + if (!\is_array($keyValue) || empty($table)) { return $this->clearPrepare(); } @@ -1026,4 +1002,57 @@ public function drop(string $table = null) return $this->query($drop); } + + public function selecting($columns = '*', ...$conditions) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->select($table, $columns, ...$conditions); + } + + public function inserting(array $keyValue) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->insert($table, $keyValue); + } + + public function replacing(array $keyValue) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->replace($table, $keyValue); + } + + public function updating(array $keyValue, ...$whereConditions) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->update($table, $keyValue, ...$whereConditions); + } + + public function deleting(...$whereConditions) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->delete($table, ...$whereConditions); + } + + public function creating(...$schemas) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->create($table, ...$schemas); + } + + /** + * Check and return the stored **global** database `table` preset with any `prefix`. + * + * @return boolean|string `false` if no preset. + */ + protected function table_prefix() + { + if (empty($this->table) || !\is_string($this->table)) + return $this->clearPrepare(); + + $table = (!empty($this->prefix) || \is_string($this->prefix)) + ? $this->prefix . $this->table + : $this->table; + + return $table; + } } diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index e3081524..295fe975 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -515,6 +515,37 @@ public function select_into(string $newTable, $fromColumns = '*', $oldTable = nu */ public function update(string $table = null, $keyValue, ...$whereConditions); + /** + * Preforms a `update` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `update` query with an array, by conditional operator array + * @param $keyValue, - table fields, assoc array with key = value (doesn't need escaped) + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/results - false for error + */ + public function updating(array $keyValue, ...$whereConditions); + /** * Does an `delete` query with an array * @param $table, - database table to access @@ -541,6 +572,36 @@ public function update(string $table = null, $keyValue, ...$whereConditions); */ public function delete(string $table = null, ...$whereConditions); + /** + * Preforms a `delete` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `delete` query with an array + * @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)` + * - In the following format: + *```js + * eq('key/Field/Column', $value, _AND), // combine next expression + * neq('key/Field/Column', $value, _OR), // will combine next expression if + * ne('key/Field/Column', $value), // the default is _AND so will combine next expression + * lt('key/Field/Column', $value) + * lte('key/Field/Column', $value) + * gt('key/Field/Column', $value) + * gte('key/Field/Column', $value) + * isNull('key/Field/Column') + * isNotNull('key/Field/Column') + * like('key/Field/Column', '_%') + * notLike('key/Field/Column', '_%') + * in('key/Field/Column', $values) + * notIn('key/Field/Column', $values) + * between('key/Field/Column', $value, $value2) + * notBetween('key/Field/Column', $value, $value2) + *``` + * @return mixed bool/results - false for error + */ + public function deleting(...$whereConditions); + /** * Does an `replace` query with an array * @param $table, - database table to access @@ -593,23 +654,50 @@ public function insert_select( ); /** - * Creates an database table and columns, by either: + * Creates an database table with columns, by either: + *```js * - array( column, datatype, ...value/options arguments ) // calls create_schema() * - column( column, datatype, ...value/options arguments ) // returns string * - primary( primary_key_label, ...primaryKeys) // returns string * - foreign( foreign_key_label, ...foreignKeys) // returns string * - unique( unique_key_label, ...uniqueKeys) // returns string - * + *``` * @param string $table, - The name of the db table that you wish to create - * @param mixed $schemas, - An array of: + * @param array ...$schemas An array of: * - * @param string $column|CONSTRAINT, - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY - * @param string $type|$constraintName, - data type for column/primary|foreign constraint name - * @param mixed $size|...$primaryForeignKeys, - * @param mixed $value, - column should be NULL or NOT NULL. If omitted, assumes NULL - * @param mixed $default - Optional. It is the value to assign to the column + * - @param string `$column | CONSTRAINT,` - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY + * - @param string `$type | $constraintName,` - data type for column/primary | foreign constraint name + * - @param mixed `$size | ...$primaryForeignKeys,` + * - @param mixed `$value,` - column should be NULL or NOT NULL. If omitted, assumes NULL + * - @param mixed `$default` - Optional. It is the value to assign to the column * * @return mixed results of query() call */ public function create(string $table = null, ...$schemas); + + /** + * Preforms a `create` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Creates an database table with columns, by either: + *```js + * - array( column, datatype, ...value/options arguments ) // calls create_schema() + * - column( column, datatype, ...value/options arguments ) // returns string + * - primary( primary_key_label, ...primaryKeys) // returns string + * - foreign( foreign_key_label, ...foreignKeys) // returns string + * - unique( unique_key_label, ...uniqueKeys) // returns string + *``` + * @param array ...$schemas An array of: + * + * - @param string `$column | CONSTRAINT,` - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY + * - @param string `$type | $constraintName,` - data type for column/primary | foreign constraint name + * - @param mixed `$size | ...$primaryForeignKeys,` + * - @param mixed `$value,` - column should be NULL or NOT NULL. If omitted, assumes NULL + * - @param mixed `$default` - Optional. It is the value to assign to the column + * + * @return mixed results of query() call + */ + public function creating(...$schemas); } diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index ebb42ecb..4a5a1268 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -31,7 +31,6 @@ notIn, between, notBetween, - select, select_into, insert_select, create_select, @@ -39,9 +38,9 @@ groupBy, having, orderBy, - insert, - update, - delete, + updating, + creating, + deleting, replace, selecting, inserting, @@ -197,11 +196,6 @@ public function testSetInstance() $this->assertFalse(setInstance()); } - public function testSelect() - { - $this->assertFalse(select('')); - } - public function testSelect_into() { $this->assertFalse(select_into('field', 'data', 'data2')); @@ -239,19 +233,19 @@ public function testOrderBy() $this->assertNotNull(orderBy('field', 'data')); } - public function testInsert() + public function testUpdating() { - $this->assertFalse(insert('field', ['data' => 'data2'])); + $this->assertFalse(updating(['data', 'data2'])); } - public function testUpdate() + public function testCreating() { - $this->assertFalse(update('field', 'data', 'data2')); + $this->assertFalse(creating(['data', 'data2'])); } - public function testDelete() + public function testDeleting() { - $this->assertFalse(delete('field', 'data', 'data2')); + $this->assertFalse(deleting('field', 'data', 'data2')); } public function testInserting() diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 8b07fbd4..ec577a4c 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -14,7 +14,6 @@ eq, like, between, - select, selecting, inserting, table_setup, @@ -267,6 +266,25 @@ public function testReplace() $this->assertEquals($this->object->replace('unit_test', array('id' => 2, 'test_key' => 'test 3')), 2); } + public function testCreatingReplacing() + { + $this->object->prepareOff(); + $this->assertFalse($this->object->replacing([])); + $this->assertFalse($this->object->creating([])); + + table_setup('unit_test'); + $this->assertEquals( + 0, + $this->object->creating( + column('id', INTR, 11, PRIMARY), + column('test_key', VARCHAR, 50) + ) + ); + + inserting(array('id' => 3, 'test_key' => 'test 3')); + $this->assertEquals(3, $this->object->replacing(array('id' => 3, 'test_key' => 'test 4'))); + } + public function testUpdate() { $this->object->prepareOff(); @@ -282,7 +300,7 @@ public function testUpdate() $this->assertEquals( 1, - $this->object->update('unit_test', $unit_test, ['test_key', EQ, 'testUpdate() 13', 'and'], ['id', '=', 13]) + $this->object->update('unit_test', $unit_test, ['test_key', EQ, 'testUpdate() 13', 'and'], ['id', '=', 13]) ); $this->assertEquals( @@ -377,7 +395,7 @@ public function testSelectingInserting() ); table_setup('unit_test'); - $this->assertEquals(1, inserting(array('id' => 1, 'test_key' => 'testing 1'))); + inserting(array('id' => 1, 'test_key' => 'testing 1')); inserting(array('id' => 2, 'test_key' => 'testing 2')); inserting(array('id' => 3, 'test_key' => 'testing 3')); @@ -576,7 +594,7 @@ public function testInsert_select() $this->assertEquals($this->object->insert_select('new_select_test', '*', 'unit_test'), 3); - $result = select('new_select_test'); + $result = $this->object->select('new_select_test'); $i = 1; foreach ($result as $row) { diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index d11b2c67..d477a8ca 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -11,9 +11,6 @@ leftJoin, column, primary, - insert, - update, - select, grouping, like, where, @@ -125,7 +122,7 @@ public function testSecureSetup() $this->assertEquals( 1, - insert( + $this->object->insert( 'new_create_test2', ['create_key' => 'test 2'] ) @@ -191,7 +188,7 @@ public function testUpdate() $unit_test['test_key'] = 'testing'; $where = ['id', '=', 1]; - $this->assertEquals(update('unit_test', $unit_test, $where), 1); + $this->assertEquals($this->object->update('unit_test', $unit_test, $where), 1); $this->assertEquals( 1, @@ -261,7 +258,7 @@ public function testSelect() } $where = array('test_key', '=', 'testing 2'); - $result = select('unit_test', 'id', $where); + $result = $this->object->select('unit_test', 'id', $where); foreach ($result as $row) { $this->assertEquals(2, $row->id); } diff --git a/tests/postgresql/postgresqlTest.php b/tests/postgresql/postgresqlTest.php index 7215caff..2eafff38 100644 --- a/tests/postgresql/postgresqlTest.php +++ b/tests/postgresql/postgresqlTest.php @@ -10,7 +10,11 @@ column, primary, eq, - pgsqlInstance + pgsqlInstance, + selecting, + inserting, + table_setup, + where }; class postgresqlTest extends EZTestCase @@ -179,6 +183,43 @@ public function testUpdate() $this->assertEquals(0, $this->object->query('DROP TABLE unit_test')); } + public function testUpdatingDeleting() + { + $this->object->prepareOff(); + $this->object->drop('unit_test'); + $this->assertFalse($this->object->updating([])); + $this->assertFalse($this->object->deleting([])); + $this->assertFalse($this->object->inserting([])); + $this->assertFalse($this->object->selecting()); + + table_setup('unit_test'); + $this->assertEquals( + 0, + $this->object->creating( + column('id', AUTO, PRIMARY), + column('test_key', VARCHAR, 50), + column('test_value', VARCHAR, 50) + ) + ); + + inserting(array('test_key' => 'test 1', 'test_value' => 'testing string 1')); + inserting(array('test_key' => 'test 2', 'test_value' => 'testing string 2')); + $result = inserting(array('test_key' => 'test 3', 'test_value' => 'testing string 3')); + + $this->assertEquals($result, 3); + + $unit_test['test_key'] = 'the key string'; + $this->assertEquals(1, $this->object->updating($unit_test, eq('test_key', 'test 1'))); + $this->assertEquals(1, $this->object->deleting(eq('test_key', 'test 3'))); + + $result = selecting('test_value', eq('test_key', 'the key string')); + foreach ($result as $row) { + $this->assertEquals('testing string 1', $row->test_value); + } + + $this->object->drop('unit_test'); + } + public function testDelete() { $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT); @@ -263,7 +304,7 @@ public function testSelect() $this->assertEquals('test 3', $row->test_key); } - $result = $this->object->select('unit_test', 'test_value', $this->object->where(eq('test_key', 'test 1'))); + $result = $this->object->select('unit_test', 'test_value', where(eq('test_key', 'test 1'))); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } From 2b839251deb19ed142480e24f692d3d29d9bb7a8 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 16 Feb 2021 01:38:20 -0500 Subject: [PATCH 145/148] bug fix, add/update preset table functions, finish removing global functions where `table` name passed in --- README.md | 5 +-- lib/ezFunctions.php | 62 +++++++++++++++++++++++++------------ lib/ezQuery.php | 12 +++---- lib/ezQueryInterface.php | 32 +++++++++++++++++++ tests/ezFunctionsTest.php | 18 +++++++---- tests/mysqli/mysqliTest.php | 7 +++-- 6 files changed, 100 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 8ad8c771..6c65d2df 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,9 @@ Mainly by: - Renamed `select` of `ez_mysqli` to `dbSelect`. - Renamed class method and behavior of `selecting` to `select`. - `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters: - - The Table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. - - This **feature** will be added to **all** database access methods, each method name will have an `ing` ending added. + - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. + - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added. + - Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`. [__version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 77e3f371..3f50cc79 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -595,7 +595,7 @@ function inserting(array $keyValue) /** * Preforms a `update` method call on a already preset `table name`, and optional `prefix` * - * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * * Does an `update` query with an array, by conditional operator array @@ -632,7 +632,7 @@ function updating(array $keyValue, ...$whereConditions) /** * Preforms a `create` method call on a already preset `table name`, and optional `prefix` * - * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * * Creates an database table with columns, by either: @@ -664,7 +664,7 @@ function creating(...$schemas) /** * Preforms a `delete` method call on a already preset `table name`, and optional `prefix` * - * This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * * Does an `delete` query with an array @@ -698,6 +698,42 @@ function deleting(...$whereConditions) : false; } + /** + * Preforms a `replace` method call on a already preset `table name`, and optional `prefix` + * + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `replace` query with an array + * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping) + * @return mixed bool/id of replaced record, or false for error + */ + function replacing(array $keyValue) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->replacing($keyValue) + : false; + } + + /** + * Preforms a `drop` method call on a already preset `table name`, and optional `prefix` + * + * This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `drop` table query if table exists. + * + * @return bool|int + */ + function dropping() + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->dropping() + : false; + } + /** * Set table `name` and `prefix` for global usage on calls to database * **method/function** *names* ending with `ing`. @@ -744,7 +780,7 @@ function set_prefix(string $append = '') } /** - * Does an select into statement by calling selecting method + * Does an `select into` statement by calling `select` method * @param $newTable, - new database table to be created * @param $fromColumns - the columns from old database table * @param $oldTable - old database table @@ -1081,7 +1117,7 @@ function fullJoin( } /** - * Returns an `UNION` SELECT SQL string, given the + * Returns an `UNION` SELECT `SQL` string, given the * - table, column fields, conditions or conditional array. * * In the following format: @@ -1112,7 +1148,7 @@ function union($table = '', $columnFields = '*', ...$conditions) } /** - * Returns an `UNION ALL` SELECT SQL string, given the + * Returns an `UNION ALL` SELECT `SQL` string, given the * - table, column fields, conditions or conditional array. * * In the following format: @@ -1174,20 +1210,6 @@ function limit($numberOf, $offset = null) : false; } - /** - * Does an `replace` query with an array - * @param $table, - database table to access - * @param $keyValue - table fields, assoc array with key = value (doesn't need escaping) - * @return mixed bool/id of replaced record, or false for error - */ - function replace($table = '', $keyValue = null) - { - $ezQuery = getInstance(); - return ($ezQuery instanceof DatabaseInterface) - ? $ezQuery->replace($table, $keyValue) - : false; - } - function ezFunctions() { return true; diff --git a/lib/ezQuery.php b/lib/ezQuery.php index a365444e..b95a21b6 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -987,12 +987,6 @@ public function alter(string $table = null, ...$schemas) return false; } - /** - * Does an `drop` table query if table exists. - * @param $table - database table to erase - * - * @return bool - */ public function drop(string $table = null) { if (empty($table)) @@ -1039,6 +1033,12 @@ public function creating(...$schemas) return ($table === false) ? false : $this->create($table, ...$schemas); } + public function dropping() + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->drop($table); + } + /** * Check and return the stored **global** database `table` preset with any `prefix`. * diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 295fe975..5c32e67a 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -610,6 +610,18 @@ public function deleting(...$whereConditions); */ public function replace(string $table = null, $keyValue); + /** + * Preforms a `replace` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `replace` query with an array + * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping) + * @return mixed bool/id of replaced record, or false for error + */ + function replacing(array $keyValue); + /** * Does an `insert` query with an array * @param $table, - database table to access @@ -700,4 +712,24 @@ public function create(string $table = null, ...$schemas); * @return mixed results of query() call */ public function creating(...$schemas); + + /** + * Does an `drop` table query if table exists. + * @param string $table - database table to erase + * + * @return bool|int + */ + public function drop(string $table = null); + + /** + * Preforms a `drop` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Does an `drop` table query if table exists. + * + * @return bool|int + */ + public function dropping(); } diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index 4a5a1268..3910b878 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -41,7 +41,8 @@ updating, creating, deleting, - replace, + dropping, + replacing, selecting, inserting, table_setup, @@ -263,6 +264,16 @@ public function testSelecting() $this->assertFalse(selecting()); } + public function testReplacing() + { + $this->assertFalse(replacing(['data' => 'data2'])); + } + + public function testDropping() + { + $this->assertFalse(dropping()); + } + public function testSet_Table() { $this->assertFalse(set_table()); @@ -272,9 +283,4 @@ public function testSet_Prefix() { $this->assertFalse(set_prefix()); } - - public function testReplace() - { - $this->assertFalse(replace('field', ['data' => 'data2'])); - } } diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index ec577a4c..ef6e0dd6 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -268,6 +268,7 @@ public function testReplace() public function testCreatingReplacing() { + $this->object->quick_connect(); $this->object->prepareOff(); $this->assertFalse($this->object->replacing([])); $this->assertFalse($this->object->creating([])); @@ -276,12 +277,14 @@ public function testCreatingReplacing() $this->assertEquals( 0, $this->object->creating( - column('id', INTR, 11, PRIMARY), + column('id', INTR, 11, AUTO, PRIMARY), column('test_key', VARCHAR, 50) ) ); - inserting(array('id' => 3, 'test_key' => 'test 3')); + inserting(array('test_key' => 'test 1')); + inserting(array('test_key' => 'test 2')); + inserting(array('test_key' => 'test 3')); $this->assertEquals(3, $this->object->replacing(array('id' => 3, 'test_key' => 'test 4'))); } From cb57b802d51871912d1fd60854b0ca2068cb1ead Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 16 Feb 2021 13:58:36 -0500 Subject: [PATCH 146/148] Update docs/doc-blocks - ready for version release, --- README.md | 120 ++++++++++++++++++++++++++----- lib/ezQueryInterface.php | 41 +++++++---- lib/ezsqlModel.php | 137 ++++++++++++++++++------------------ lib/ezsqlModelInterface.php | 134 +++++++++++++++++------------------ 4 files changed, 266 insertions(+), 166 deletions(-) diff --git a/README.md b/README.md index 6c65d2df..bb5e21a5 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,11 @@ ***A class to make it very easy to deal with database connections.*** -This is a [WIP] of [__version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**. +This is [__Version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**. Mainly by: - - The use of `namespace` in the `global` functions **ezFunctions.php** file. + +- The use of `namespace` in the `global` functions **ezFunctions.php** file. Usage of the **global** functions will require the user to begin a `.php` file something like: ```php @@ -25,15 +26,16 @@ Mainly by: inserting, }; ``` - - Class properties that was accessible by magic methods `get/set`, now PSR 1 camelCase. - - Renamed `select` of `ez_mysqli` to `dbSelect`. - - Renamed class method and behavior of `selecting` to `select`. - - `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters: - - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. - - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added. - - Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`. -[__version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. +- Class properties that was accessible by magic methods `get/set`, now PSR 1 camelCase. +- Renamed `select` of `ez_mysqli` to `dbSelect`. +- Renamed class method and behavior of `selecting` to `select`. +- `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters: + - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. + - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added. +- Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`. + +[__Version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. [__Version 3__](https://github.com/ezSQL/ezsql/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features. @@ -138,7 +140,7 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou * `orderBy($orderBy, $order);` * `limit($numberOf, $offset = null)` * `where( ...$whereConditions);` -* `selecting(string $table = null, $columnFields = '*', ...$conditions);` +* `select(string $table = null, $columnFields = '*', ...$conditions);` * `create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions);` * `select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions);` * `update(string $table = null, $keyAndValue, ...$whereConditions);` @@ -181,11 +183,18 @@ grouping( eq(key, value, combiner ), eq(key, value, combiner ) ) ``` ```php -// Supply the the whole query string, and placing '?' within -// With the same number of arguments in an array. -// It will determine arguments type, execute, and return results. +// Note: The usage of this method will require the user/developer to check +// if `query_string` or `param_array` is valid. +// +// This is really an `private` internal method for other shortcut methods, +// it's made public for `class development` usage only. +// +// +// Supply the the whole `query` string, and placing '?' within, with the same number of arguments in an array. +// It will then determine arguments type, execute, and return results. query_prepared(string $query_string, array $param_array); -// Will need to call to get last successful query result, will return an object array +// You will need to call this method to get last successful query result. +// It wll return an object array. queryResult(); ``` @@ -203,13 +212,13 @@ $db->insert('profile', $values); $db->insert('profile', ['name' => 'john john', 'email' => 'john@email', 'phone' => 123456]); // returns result set given the table name, column fields, and ...conditions -$result = $db->selecting('profile', 'phone', eq('email', $email), between('id', 1, $values)); +$result = $db->select('profile', 'phone', eq('email', $email), between('id', 1, $values)); foreach ($result as $row) { echo $row->phone; } -$result = $db->selecting('profile', 'name, email', +$result = $db->select('profile', 'name, email', // Conditionals can also be called, stacked with other functions like: // innerJoin(), leftJoin(), rightJoin(), fullJoin() // as (leftTable, rightTable, leftColumn, rightColumn, tableAs, equal condition), @@ -245,6 +254,83 @@ foreach ($result as $row) { } ``` +Most of shortcut methods have counter **global** _functions_ available. +They can only be access by beginning your `.php` file like: + +```php +use function ezsql\functions\functionBelow; +// Or as here, a complete list. +use function ezsql\functions\{ + database, + mysqlInstance, + pgsqlInstance, + mssqlInstance, + sqliteInstance, + pdoInstance, + tagInstance, + setInstance, + getInstance, + clearInstance, +/// + getVendor, + to_string, + cleanInput, + createCertificate, +/// + column, + primary, + foreign, + unique, + index, + addColumn, + dropColumn, +/// + eq, + neq, + ne, + lt, + lte, + gt, + gte, + isNull, + isNotNull, + like, + in, + notLike, + notIn, + between, + notBetween, +/// + select_into, + insert_select, + create_select, + where, + grouping, + groupBy, + having, + orderBy, + limit, + innerJoin, + leftJoin, + rightJoin, + fullJoin, + union, + unionAll, +/// + creating, + deleting, + dropping, + replacing, + selecting, + inserting, + table_setup, + set_table, + set_prefix +}; +``` + +For the functions **usage/docs** see [ezFunctions.php](https://github.com/ezSQL/ezsql/blob/v5/lib/ezFunctions.php). + ## For Authors and **[Contributors](https://github.com/ezSQL/ezsql/blob/master/CONTRIBUTORS.md)** ## Contributing diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 5c32e67a..528a80b1 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -1,5 +1,7 @@ * @@ -23,11 +25,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the MIT license. + * and is licensed under the **MIT** license. */ - -namespace ezsql; - interface ezQueryInterface { /** @@ -403,6 +402,23 @@ public function select(string $table = null, $columnFields = '*', ...$conditions * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * + * Returns an `SQL string` or `result` set, given the + * - column fields, conditions or conditional array. + * + * In the following format: + * ```php + * selecting( + * columns, + * innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition), + * where( eq( columns, values, _AND ), like( columns, _d ) ), + * groupBy( columns ), + * having( between( columns, values1, values2 ) ), + * orderBy( columns, desc ), + * limit( numberOfRecords, offset ), + * union(table, columnFields, conditions), // Returns an select SQL string with `UNION` + * unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL` + *); + * ``` * @param mixed $columns fields, string or array * @param mixed ...$conditions - of the following parameters: * @@ -420,12 +436,21 @@ public function select(string $table = null, $columnFields = '*', ...$conditions */ public function selecting($columns = '*', ...$conditions); + /** + * Does an `insert` query with an array + * @param $table, - database table to access + * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) + * @return mixed bool/id of inserted record, or false for error + */ + public function insert(string $table = null, $keyValue); + /** * Preforms a `insert` method call on a already preset `table name`, and optional `prefix` * * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. * + * Does an `insert` query with an array * @param array $keyValue - table fields, assoc array with key = value (doesn't need escaped) * @return int|bool bool/id of inserted record, or false for error */ @@ -622,14 +647,6 @@ public function replace(string $table = null, $keyValue); */ function replacing(array $keyValue); - /** - * Does an `insert` query with an array - * @param $table, - database table to access - * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) - * @return mixed bool/id of inserted record, or false for error - */ - public function insert(string $table = null, $keyValue); - /** * Does an `insert into select` statement by calling insert method helper then `select` method * @param $toTable, - database table to insert table into diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 1493821c..eaa77cf0 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -7,78 +7,77 @@ use function ezsql\functions\getVendor; /** - * Core class containing common functions to manipulate query result - * sets once returned + * Core class containing common functions to manipulate **query** `result sets` once returned. * - * @method set/get{property} - a property that needs to be accessed + * The class properties can be accessed with either a `set` or `get` prefix as a function. * - * @method void setDebugAll($args); - * @method void setTrace($args); - * @method void setDebugCalled($args); - * @method void setVarDumpCalled($args); - * @method void setShowErrors($args); - * @method void setNumQueries($args); - * @method void setConnQueries($args); - * @method void setCapturedErrors($args); - * @method void setCacheDir($args); - * @method void setUseDiskCache($args); - * @method void setCacheTimeout($args); - * @method void setCacheQueries($args); - * @method void setCacheInserts($args); - * @method void setNumRows($args); - * @method void setDbConnectTime($args); - * @method void setSqlLogFile($args); - * @method void setProfileTimes($args); - * @method void setInsertId($args); - * @method void setLastQuery($args); - * @method void setLastError($args); - * @method void setColInfo($args); - * @method void setTimers($args); - * @method void setTotalQueryTime($args); - * @method void setTraceLog($args); - * @method void setUseTraceLog($args); - * @method void setDoProfile($args); - * @method void setLastResult($args); - * @method void setFromDiskCache($args); - * @method void setDebugEchoIsOn($args); - * @method void setFuncCall($args); - * @method void setAllFuncCalls($args); - * @method void setTable($name); - * @method void setPrefix($append); + * @method void setDebugAll($args) + * @method void setTrace($args) + * @method void setDebugCalled($args) + * @method void setVarDumpCalled($args) + * @method void setShowErrors($args) + * @method void setNumQueries($args) + * @method void setConnQueries($args) + * @method void setCapturedErrors($args) + * @method void setCacheDir($args) + * @method void setUseDiskCache($args) + * @method void setCacheTimeout($args) + * @method void setCacheQueries($args) + * @method void setCacheInserts($args) + * @method void setNumRows($args) + * @method void setDbConnectTime($args) + * @method void setSqlLogFile($args) + * @method void setProfileTimes($args) + * @method void setInsertId($args) + * @method void setLastQuery($args) + * @method void setLastError($args) + * @method void setColInfo($args) + * @method void setTimers($args) + * @method void setTotalQueryTime($args) + * @method void setTraceLog($args) + * @method void setUseTraceLog($args) + * @method void setDoProfile($args) + * @method void setLastResult($args) + * @method void setFromDiskCache($args) + * @method void setDebugEchoIsOn($args) + * @method void setFuncCall($args) + * @method void setAllFuncCalls($args) + * @method void setTable($name) + * @method void setPrefix($append) * - * @method string getDebugAll(); - * @method string getTrace(); - * @method string getDebugCalled(); - * @method string getVarDumpCalled(); - * @method string getShowErrors(); - * @method string getNumQueries(); - * @method string getConnQueries(); - * @method string getCapturedErrors(); - * @method string getCacheDir(); - * @method string getUseDiskCache(); - * @method string getCacheTimeout(); - * @method string getCacheQueries(); - * @method string getCacheInserts(); - * @method string getNumRows(); - * @method string getDbConnectTime(); - * @method string getSqlLogFile(); - * @method string getProfileTimes(); - * @method string getInsertId(); - * @method string getLastQuery(); - * @method string getLastError(); - * @method string getColInfo(); - * @method string getTimers(); - * @method string getTotalQueryTime(); - * @method string getTraceLog(); - * @method string getUseTraceLog(); - * @method string getDoProfile(); - * @method string getLastResult(); - * @method string getFromDiskCache(); - * @method string getDebugEchoIsOn(); - * @method string getFuncCall(); - * @method string getAllFuncCalls(); - * @method string getTable(); - * @method string getPrefix(); + * @method string getDebugAll() + * @method string getTrace() + * @method string getDebugCalled() + * @method string getVarDumpCalled() + * @method string getShowErrors() + * @method string getNumQueries() + * @method string getConnQueries() + * @method string getCapturedErrors() + * @method string getCacheDir() + * @method string getUseDiskCache() + * @method string getCacheTimeout() + * @method string getCacheQueries() + * @method string getCacheInserts() + * @method string getNumRows() + * @method string getDbConnectTime() + * @method string getSqlLogFile() + * @method string getProfileTimes() + * @method string getInsertId() + * @method string getLastQuery() + * @method string getLastError() + * @method string getColInfo() + * @method string getTimers() + * @method string getTotalQueryTime() + * @method string getTraceLog() + * @method string getUseTraceLog() + * @method string getDoProfile() + * @method string getLastResult() + * @method string getFromDiskCache() + * @method string getDebugEchoIsOn() + * @method string getFuncCall() + * @method string getAllFuncCalls() + * @method string getTable() + * @method string getPrefix() */ class ezsqlModel extends ezQuery implements ezsqlModelInterface { diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 259564a3..7dc39ffe 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -3,75 +3,73 @@ namespace ezsql; /** - * @method set/get{property} - a property that needs to be accessed + * @method void setDebugAll($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setTrace($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setDebugCalled($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setVarDumpCalled($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setShowErrors($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setNumQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setConnQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setCapturedErrors($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setCacheDir($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setUseDiskCache($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setCacheTimeout($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setCacheQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setCacheInserts($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setNumRows($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setDbConnectTime($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setSqlLogFile($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setProfileTimes($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setInsertId($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setLastQuery($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setLastError($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setColInfo($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setTimers($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setTotalQueryTime($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setTraceLog($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setUseTraceLog($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setDoProfile($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setLastResult($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setFromDiskCache($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setDebugEchoIsOn($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setFuncCall($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setAllFuncCalls($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setTable($name); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setPrefix($append); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. * - * @method void setDebugAll($args); - * @method void setTrace($args); - * @method void setDebugCalled($args); - * @method void setVarDumpCalled($args); - * @method void setShowErrors($args); - * @method void setNumQueries($args); - * @method void setConnQueries($args); - * @method void setCapturedErrors($args); - * @method void setCacheDir($args); - * @method void setUseDiskCache($args); - * @method void setCacheTimeout($args); - * @method void setCacheQueries($args); - * @method void setCacheInserts($args); - * @method void setNumRows($args); - * @method void setDbConnectTime($args); - * @method void setSqlLogFile($args); - * @method void setProfileTimes($args); - * @method void setInsertId($args); - * @method void setLastQuery($args); - * @method void setLastError($args); - * @method void setColInfo($args); - * @method void setTimers($args); - * @method void setTotalQueryTime($args); - * @method void setTraceLog($args); - * @method void setUseTraceLog($args); - * @method void setDoProfile($args); - * @method void setLastResult($args); - * @method void setFromDiskCache($args); - * @method void setDebugEchoIsOn($args); - * @method void setFuncCall($args); - * @method void setAllFuncCalls($args); - * @method void setTable($name); - * @method void setPrefix($append); - * - * @method string getDebugAll(); - * @method string getTrace(); - * @method string getDebugCalled(); - * @method string getVarDumpCalled(); - * @method string getShowErrors(); - * @method string getNumQueries(); - * @method string getConnQueries(); - * @method string getCapturedErrors(); - * @method string getCacheDir(); - * @method string getUseDiskCache(); - * @method string getCacheTimeout(); - * @method string getCacheQueries(); - * @method string getCacheInserts(); - * @method string getNumRows(); - * @method string getDbConnectTime(); - * @method string getSqlLogFile(); - * @method string getProfileTimes(); - * @method string getInsertId(); - * @method string getLastQuery(); - * @method string getLastError(); - * @method string getColInfo(); - * @method string getTimers(); - * @method string getTotalQueryTime(); - * @method string getTraceLog(); - * @method string getUseTraceLog(); - * @method string getDoProfile(); - * @method string getLastResult(); - * @method string getFromDiskCache(); - * @method string getDebugEchoIsOn(); - * @method string getFuncCall(); - * @method string getAllFuncCalls(); - * @method string getTable(); - * @method string getPrefix(); + * @method string getDebugAll(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getTrace(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getDebugCalled(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getVarDumpCalled(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getShowErrors(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getNumQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getConnQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getCapturedErrors(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getCacheDir(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getUseDiskCache(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getCacheTimeout(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getCacheQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getCacheInserts(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getNumRows(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getDbConnectTime(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getSqlLogFile(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getProfileTimes(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getInsertId(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getLastQuery(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getLastError(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getColInfo(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getTimers(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getTotalQueryTime(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getTraceLog(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getUseTraceLog(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getDoProfile(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getLastResult(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getFromDiskCache(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getDebugEchoIsOn(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getFuncCall(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getAllFuncCalls(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getTable(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getPrefix(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. */ interface ezsqlModelInterface { From 669c4383ff5ef72321b4829260e8f7b793617c22 Mon Sep 17 00:00:00 2001 From: techno-express Date: Tue, 16 Feb 2021 15:20:52 -0500 Subject: [PATCH 147/148] Merge branch 'master' into v5 --- lib/ConfigAbstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ConfigAbstract.php b/lib/ConfigAbstract.php index 9e365758..0d93f6eb 100644 --- a/lib/ConfigAbstract.php +++ b/lib/ConfigAbstract.php @@ -51,7 +51,7 @@ * @method string getOptions(); * @method string getToMysql(); * @method bool getIsFile(); - * @method bool getToMssql();getToMssql + * @method bool getToMssql(); * @method string getPath(); */ abstract class ConfigAbstract From fc9797e6aaef561bffd04d1e590356341076ff6d Mon Sep 17 00:00:00 2001 From: techno-express Date: Fri, 19 Feb 2021 20:04:49 -0500 Subject: [PATCH 148/148] Merge branch 'master' into v5 --- README.md | 34 +++- composer.json | 7 +- lib/Config.php | 37 ---- lib/ConfigAbstract.php | 33 +++- lib/ConfigInterface.php | 66 ++++++- lib/Constants.php | 8 +- lib/Database.php | 31 ++- lib/ezFunctions.php | 166 +++++++++++++--- lib/ezQuery.php | 31 +-- lib/ezQueryInterface.php | 44 +++++ lib/ezResultset.php | 4 +- lib/ezSchema.php | 9 +- lib/ezsqlModel.php | 282 ++++++++++++++++++++-------- lib/ezsqlModelInterface.php | 278 ++++++++++++++++++++------- tests/ezFunctionsTest.php | 21 ++- tests/ezQueryTest.php | 7 +- tests/ezSchemaTest.php | 14 +- tests/ezsqlModelTest.php | 14 +- tests/mysqli/ezResultsetTest.php | 45 +++-- tests/mysqli/mysqliTest.php | 72 ++++++- tests/postgresql/postgresqlTest.php | 14 +- 21 files changed, 919 insertions(+), 298 deletions(-) diff --git a/README.md b/README.md index bb5e21a5..40a17049 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Total Downloads](https://poser.pugx.org/ezsql/ezsql/downloads)](https://packagist.org/packages/ezsql/ezsql) ***A class to make it very easy to deal with database connections.*** +*An universal interchangeable **CRUD** system.* This is [__Version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**. @@ -34,6 +35,9 @@ Mainly by: - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned. - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added. - Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`. +- renamed cleanInput to clean_string +- renamed createCertificate to create_certificate +- added global get_results to return result sets in different formats [__Version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3. @@ -83,7 +87,7 @@ ___General Methods___ string $path = '.'._DS ); secureReset(); - createCertificate(string $privatekeyFile = certificate.key, + create_certificate(string $privatekeyFile = certificate.key, string $certificateFile = certificate.crt, string $signingFile = certificate.csr, string $ssl_path = null, array $details = [commonName => localhost] @@ -96,6 +100,7 @@ ___Shortcut Table Methods___ primary(string $primaryName, ...$primaryKeys); index(string $indexName, ...$indexKeys); drop(string $table); + Example ```php @@ -147,6 +152,9 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou * `delete(string $table = null, ...$whereConditions);` * `replace(string $table = null, $keyAndValue);` * `insert(string $table = null, $keyAndValue);` +* `create(string $table = null, ...$schemas);` +* `drop(string $table = null);` +* `alter(string $table = null, ...$alteringSchema);` * `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions);` ```php @@ -239,6 +247,9 @@ $result = $db->select('profile', 'name, email', foreach ($result as $row) { echo $row->name.' '.$row->email; } + +// To get results in `JSON` format +$json = get_results(JSON, $db); ``` #### Example for using prepare statements directly, no shortcut SQL methods used @@ -247,7 +258,9 @@ foreach ($result as $row) { $db->query_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? );', [$user, $address, $number]); $db->query_prepared('SELECT name, email FROM profile WHERE phone = ? OR id != ?', [$number, 5]); -$result = $db->queryResult(); // the last query that has results are stored in `last_result` protected property +$result = $db->queryResult(); // the last query that has results are stored in `lastResult` protected property +// Or for results in other formats use the global function, will use global database instance if no `$db` supplied +$result = get_results(/* OBJECT|ARRAY_A|ARRAY_N|JSON */, $db); // Defaults to `OBJECT` foreach ($result as $row) { echo $row->name.' '.$row->email; @@ -271,11 +284,11 @@ use function ezsql\functions\{ setInstance, getInstance, clearInstance, + get_vendor, /// - getVendor, to_string, - cleanInput, - createCertificate, + clean_string, + create_certificate, /// column, primary, @@ -284,6 +297,7 @@ use function ezsql\functions\{ index, addColumn, dropColumn, + changingColumn, /// eq, neq, @@ -301,9 +315,6 @@ use function ezsql\functions\{ between, notBetween, /// - select_into, - insert_select, - create_select, where, grouping, groupBy, @@ -323,9 +334,14 @@ use function ezsql\functions\{ replacing, selecting, inserting, + altering, + get_results, table_setup, set_table, - set_prefix + set_prefix, + select_into, + insert_select, + create_select, }; ``` diff --git a/composer.json b/composer.json index 29f7ef48..912fedd3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,9 @@ { "name": "ezsql/ezsql", - "description": "Advance database access library. Make interacting with a database ridiculously easy.", + "description": "Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.", "keywords": [ + "crud", + "dba", "mysql", "mysqli", "postgresql", @@ -13,8 +15,7 @@ "sqlite3", "database", "abstraction", - "sql", - "dba" + "sql" ], "license": [ "LGPL-3.0-or-later", diff --git a/lib/Config.php b/lib/Config.php index f2510762..71cd75bf 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -31,43 +31,6 @@ public function __construct(string $driver = '', array $arguments = null) } } - /** - * Setup Connections for each SQL database class - * @param string $driver - The vendor's SQL database driver name - * @param string|array $arguments In the following: - * - * - user|args[0][1] // The database user name - * - password|args[1][2] // The database users password - * - database|args[1][2] // The name of the database - * - host|args[3] // The host name or IP address of the database server, - * Default is localhost - * - port|args[4] // The database TCP/IP port, - * Default is: 5432 - PostgreSQL, 3306 - MySQL - * - * for: mysqli - * - (username, password, database, host, port, charset) - * - charset|args[5] // The database charset, - * Default is empty string - * - * for: postgresql - * - (username, password, database, host, port) - * - * for: sqlserver - * - (username, password, database, host, convertMysqlToMssqlQuery) - * - convertMysqlToMssqlQuery[4] // convert Queries in MySql syntax to MS-SQL syntax - * Default is false - * - * for: pdo - * - (dsn, username, password, options, isFile?) - * - dsn |args[0] // The PDO DSN connection parameter string - * - options|args[3] // Array for setting connection options as MySQL - * - isFile|args[4] // File based databases like SQLite don't need - * user and password, they work with path in the dsn parameter - * Default is false - * - * for: sqlite3 - * - (filePath, database) - filePath|args[0] // The path to open an SQLite database - */ public static function initialize(string $driver = '', array $arguments = null) { return new self($driver, $arguments); diff --git a/lib/ConfigAbstract.php b/lib/ConfigAbstract.php index 0d93f6eb..72f6fb68 100644 --- a/lib/ConfigAbstract.php +++ b/lib/ConfigAbstract.php @@ -24,35 +24,66 @@ namespace ezsql; /** - * @method set/get{property} - a property that needs to be accessed * * @method void setDriver($args); + * Database Sql driver name * @method void setDsn($args); + * The PDO connection parameter string, database server in the DSN parameters * @method void setUser($args); + * Database user name * @method void setPassword($args); + * Database password for the given user * @method void setName($args); + * Database name * @method void setHost($args); + * Host name or IP address * @method void setPort($args); + * TCP/IP port of PostgreSQL/MySQL * @method void setCharset($args); + * Database charset * @method void setOptions($args); + * The PDO array for connection options, MySQL connection charset, for example * @method void setIsFile($args); + * Check PDO for whether it is a file based database connection, for example to a SQLite + * database file, or not * @method void setToMssql($args); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method void setToMysql($args); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method void setPath($args); + * The path to open an SQLite database * * @method string getDriver(); + * Database Sql driver name * @method string getDsn(); + * The PDO connection parameter string, database server in the DSN parameters * @method string getUser(); + * Database user name * @method string getPassword() + * Database password for the given user * @method string getName(); + * Database name * @method string getHost(); + * Host name or IP address * @method string getPort(); + * TCP/IP port of PostgreSQL/MySQL * @method string getCharset(); + * Database charset * @method string getOptions(); + * The PDO array for connection options, MySQL connection charset, for example * @method string getToMysql(); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method bool getIsFile(); + * Check PDO for whether it is a file based database connection, for example to a SQLite + * database file, or not * @method bool getToMssql(); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method string getPath(); + * The path to open an SQLite database */ abstract class ConfigAbstract { diff --git a/lib/ConfigInterface.php b/lib/ConfigInterface.php index 681b54c7..b3f7feee 100644 --- a/lib/ConfigInterface.php +++ b/lib/ConfigInterface.php @@ -4,40 +4,100 @@ /** * @method void setDriver($args); + * Database Sql driver name * @method void setDsn($args); + * The PDO connection parameter string, database server in the DSN parameters * @method void setUser($args); + * Database user name * @method void setPassword($args); + * Database password for the given user * @method void setName($args); + * Database name * @method void setHost($args); + * Host name or IP address * @method void setPort($args); + * TCP/IP port of PostgreSQL/MySQL * @method void setCharset($args); + * Database charset * @method void setOptions($args); + * The PDO array for connection options, MySQL connection charset, for example * @method void setIsFile($args); + * Check PDO for whether it is a file based database connection, for example to a SQLite + * database file, or not * @method void setToMssql($args); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method void setToMysql($args); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method void setPath($args); + * The path to open an SQLite database * * @method string getDriver(); + * Database Sql driver name * @method string getDsn(); + * The PDO connection parameter string, database server in the DSN parameters * @method string getUser(); + * Database user name * @method string getPassword() + * Database password for the given user * @method string getName(); + * Database name * @method string getHost(); + * Host name or IP address * @method string getPort(); + * TCP/IP port of PostgreSQL/MySQL * @method string getCharset(); + * Database charset * @method string getOptions(); + * The PDO array for connection options, MySQL connection charset, for example * @method bool getIsFile(); - * @method bool getToMysql(); + * Check PDO for whether it is a file based database connection, for example to a SQLite + * database file, or not * @method bool getToMssql(); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. + * @method bool getToMysql(); + * If we want to convert Queries in MySql syntax to MS-SQL syntax. + * Yes, there are some differences in query syntax. * @method string getPath(); + * The path to open an SQLite database */ interface ConfigInterface { /** * Setup Connections for each SQL database class * - * @param string $driver - * @param string|array $arguments + * @param string $driver - The vendor's SQL database driver name + * @param array $arguments SQL connection parameters, in the following: + *```js + * [ + * user, // The database user name. + * password, // The database users password. + * database, // The name of the database. + * host, // The host name or IP address of the database server. Default is localhost + * port // The database TCP/IP port. Default is: 5432 - PostgreSQL, 3306 - MySQL + * ] + *``` + * for: **mysqli** - (`username`, `password`, `database`, `host`, `port`, `charset`) + * - `charset` // The database charset, + * Default is empty string + * + * for: **postgresql** - (`username`, `password`, `database`, `host`, `port`) + * + * for: **sqlserver** - (`username`, `password`, `database`, `host`, `convertMysqlToMssqlQuery`) + * - `convertMysqlToMssqlQuery` // convert Queries in MySql syntax to MS-SQL syntax + * Default is false + * + * for: **pdo** - (`dsn`, `username`, `password`, `options`, `isFile`?) + * - `dsn` // The PDO DSN connection parameter string + * - `options` // Array for setting connection options as MySQL + * - `isFile` // File based databases like SQLite don't need + * user and password, they work with path in the dsn parameter + * Default is false + * + * for: **sqlite3** - (`filePath`, `database`) + * - `filePath` // The path to open an SQLite database */ public static function initialize(string $driver = '', array $arguments = null); } diff --git a/lib/Constants.php b/lib/Constants.php index 6c0fbce0..959f1e4d 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -5,10 +5,12 @@ /** * ezsqlModel Constants */ - \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.0.0'); + \defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.1.0'); \defined('OBJECT') or \define('OBJECT', 'OBJECT'); \defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A'); \defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N'); + // Use to set get_result output as json + \define('JSON', 'json'); // Error messages \define('MISSING_CONFIGURATION', 'Fatal Error: Missing configuration details to connect to database'); @@ -17,8 +19,6 @@ // ezQuery prepare placeholder/positional tag \define('_TAG', '__ez__'); - // Use to set get_result output as json - \define('_JSON', 'json'); /** * Operator boolean expressions. @@ -174,7 +174,7 @@ \define('DROP', 'DROP COLUMN'); \define('CHANGE', 'CHANGE COLUMN'); \define('ALTER', 'ALTER COLUMN'); - \define('MODIFY', 'MODIFY'); + \define('MODIFY', 'MODIFY COLUMN'); \define('RENAME', 'RENAME TO'); \define('CHANGER', '__modifyingColumns__'); diff --git a/lib/Database.php b/lib/Database.php index b27cc78c..0b028739 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -32,7 +32,36 @@ public function __wakeup() * Initialize and connect a vendor database. * * @param string $vendor SQL driver - * @param array $setting SQL connection parameters + * @param array $setting SQL connection parameters, in the following: + *```js + * [ + * user, // The database user name. + * password, // The database users password. + * database, // The name of the database. + * host, // The host name or IP address of the database server. Default is localhost + * port // The database TCP/IP port. Default is: 5432 - PostgreSQL, 3306 - MySQL + * ] + *``` + * for: **mysqli** - (`username`, `password`, `database`, `host`, `port`, `charset`) + * - `charset` // The database charset, + * Default is empty string + * + * for: **postgresql** - (`username`, `password`, `database`, `host`, `port`) + * + * for: **sqlserver** - (`username`, `password`, `database`, `host`, `convertMysqlToMssqlQuery`) + * - `convertMysqlToMssqlQuery` // convert Queries in MySql syntax to MS-SQL syntax + * Default is false + * + * for: **pdo** - (`dsn`, `username`, `password`, `options`, `isFile`?) + * - `dsn` // The PDO DSN connection parameter string + * - `options` // Array for setting connection options as MySQL + * - `isFile` // File based databases like SQLite don't need + * user and password, they work with path in the dsn parameter + * Default is false + * + * for: **sqlite3** - (`filePath`, `database`) + * - `filePath` // The path to open an SQLite database + * * @param string $tag Store the instance for later use * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 3f50cc79..56c2d7ff 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -16,9 +16,38 @@ * Initialize and connect a vendor's database. * * @param string $sqlDriver - SQL driver - * @param array $connectionSetting - SQL connection parameters + * @param array $connectionSetting SQL connection parameters, in the following: + *```js + * [ + * user, // The database user name. + * password, // The database users password. + * database, // The name of the database. + * host, // The host name or IP address of the database server. Default is localhost + * port // The database TCP/IP port. Default is: 5432 - PostgreSQL, 3306 - MySQL + * ] + *``` + * for: **mysqli** - (`username`, `password`, `database`, `host`, `port`, `charset`) + * - `charset` // The database charset, + * Default is empty string + * + * for: **postgresql** - (`username`, `password`, `database`, `host`, `port`) + * + * for: **sqlserver** - (`username`, `password`, `database`, `host`, `convertMysqlToMssqlQuery`) + * - `convertMysqlToMssqlQuery` // convert Queries in MySql syntax to MS-SQL syntax + * Default is false + * + * for: **pdo** - (`dsn`, `username`, `password`, `options`, `isFile`?) + * - `dsn` // The PDO DSN connection parameter string + * - `options` // Array for setting connection options as MySQL + * - `isFile` // File based databases like SQLite don't need + * user and password, they work with path in the dsn parameter + * Default is false + * + * for: **sqlite3** - (`filePath`, `database`) + * - `filePath` // The path to open an SQLite database + * * @param string $instanceTag - Store the instance for later use - * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|ezsql\Database\ez_sqlite3|ezsql\Database\ez_mysqli + * @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli */ function database(string $sqlDriver = null, array $connectionSetting = null, string $instanceTag = null) { @@ -29,7 +58,7 @@ function database(string $sqlDriver = null, array $connectionSetting = null, str * Returns an already initialized database instance that was created with an tag. * * @param string $getTag - An stored tag instance - * @return ezsql\Database\ez_pdo|ezsql\Database\ez_pgsql|ezsql\Database\ez_sqlsrv|ezsql\Database\ez_sqlite3|ezsql\Database\ez_mysqli + * @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli */ function tagInstance(string $getTag = null) { @@ -39,10 +68,11 @@ function tagInstance(string $getTag = null) /** * Initialize an mysqli database. * - * @param array $databaseSetting - SQL connection parameters + * @param array $databaseSetting SQL connection parameters + * - [ `username`, `password`, `database`, host, port, charset ] * @param string $instanceTag - Store the instance for later use * - * @return ezsql\Database\ez_mysqli + * @return \ezsql\Database\ez_mysqli */ function mysqlInstance(array $databaseSetting = null, string $instanceTag = null) { @@ -52,10 +82,11 @@ function mysqlInstance(array $databaseSetting = null, string $instanceTag = null /** * Initialize an pgsql database. * - * @param array $databaseSetting - SQL connection parameters + * @param array $databaseSetting SQL connection parameters + * - [ `username`, `password`, `database`, host, port ] * @param string $instanceTag - Store the instance for later use * - * @return ezsql\Database\ez_pgsql + * @return \ezsql\Database\ez_pgsql */ function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null) { @@ -68,7 +99,7 @@ function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null * @param array $databaseSetting - SQL connection parameters * @param string $instanceTag - Store the instance for later use * - * @return ezsql\Database\ez_sqlsrv + * @return \ezsql\Database\ez_sqlsrv */ function mssqlInstance(array $databaseSetting = null, string $instanceTag = null) { @@ -81,7 +112,7 @@ function mssqlInstance(array $databaseSetting = null, string $instanceTag = null * @param array $databaseSetting - SQL connection parameters * @param string $instanceTag - Store the instance for later use * - * @return ezsql\Database\ez_pdo + * @return \ezsql\Database\ez_pdo */ function pdoInstance(array $databaseSetting = null, string $instanceTag = null) { @@ -94,7 +125,7 @@ function pdoInstance(array $databaseSetting = null, string $instanceTag = null) * @param array $databaseSetting - SQL connection parameters * @param string $instanceTag - Store the instance for later use * - * @return ezsql\Database\ez_sqlite3 + * @return \ezsql\Database\ez_sqlite3 */ function sqliteInstance(array $databaseSetting = null, string $instanceTag = null) { @@ -102,13 +133,14 @@ function sqliteInstance(array $databaseSetting = null, string $instanceTag = nul } /** - * Returns the current global database vendor being used. + * Returns database vendor string, either the global instance, or provided class instance. + * @param \ezsql\DatabaseInterface|null $instance * * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` */ - function getVendor() + function get_vendor(DatabaseInterface $instance = null) { - return ezSchema::vendor(); + return ezSchema::vendor($instance); } /** @@ -122,24 +154,27 @@ function to_string($arrays, $separation = ',') } /** - * Creates an database column, - * - column, datatype, value/options with the given arguments. + * Creates an database column as: + * - `column`, data`type`, ...value/options `arguments`. * - * // datatype are global CONSTANTS and can be written out like: + * // datatype are global `CONSTANTS` and can be written out like: * - VARCHAR, 32, notNULL, PRIMARY, SEQUENCE|AUTO, .... * // SEQUENCE|AUTO constants will replaced with the proper auto sequence for the SQL driver * - * @param string $column|CONSTRAINT, - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY - * @param string $type|$constraintName, - data type for column/primary|foreign constraint name - * @param mixed $size|...$primaryForeignKeys, - * @param mixed $value, - column should be NULL or NOT NULL. If omitted, assumes NULL - * @param mixed $default - Optional. It is the value to assign to the column + * @param string $column | `CONSTRAINT`, - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY + * @param string $type | constraintName, - data type for column/primary|foreign constraint name + * @param mixed ...$arguments any remainder assignments `ordered` like: + * - @param mixed $size, or/and + * - @param mixed $value, - or/and column should be `NULLS`|`notNULL`. If omitted, assumes `NULLS` + * - @param mixed $default, - or/and Optional. It is the value to assign to the column + * - @param mixed $autoNumber, or/and `AUTO` for vendor's auto numbering + * - @param mixed $primaryForeignKeys | or/and `PRIMARY`|`FOREIGN` * * @return string|bool - SQL schema string, or false for error */ - function column(string $column = null, string $type = null, ...$args) + function column(string $column = null, string $type = null, ...$arguments) { - return ezSchema::column($column, $type, ...$args); + return ezSchema::column($column, $type, ...$arguments); } function primary(string $primaryName, ...$primaryKeys) @@ -175,6 +210,11 @@ function dropColumn(string $columnName, ...$data) return column(\DROP, $columnName, ...$data); } + function changingColumn(string $columnName, ...$datatype) + { + return column(\CHANGER, $columnName, ...$datatype); + } + /** * Creates self signed certificate * @@ -198,7 +238,7 @@ function dropColumn(string $columnName, ...$data) * * @return string certificate path */ - function createCertificate( + function create_certificate( string $privatekeyFile = 'certificate.key', string $certificateFile = 'certificate.crt', string $signingFile = 'certificate.csr', @@ -505,6 +545,42 @@ function getInstance() return ($ezInstance instanceof ezQueryInterface) ? $ezInstance : null; } + /** + * Get multiple row result set from the database (previously cached results). + * Returns a multi dimensional array. + * + * Each element of the array contains one row of results and can be + * specified to be either an `object`, `json`, `associative array` or `numerical + * array`. + * - If no results are found then the function returns `false`, + * enabling you to use the function within logic statements such as if. + * + * **OBJECT** - `Returning results as an object` is the quickest way to get and + * display results. It is also useful that you are able to put + * `$object->var` syntax directly inside print statements without + * having to worry about causing php parsing errors. + * + * **ARRAY_A** - `Returning results as an associative array` is useful if you would + * like dynamic access to column names. + * + * **ARRAY_N** - `Returning results as a numerical array` is useful if you are using + * completely dynamic queries with varying column names but still need + * a way to get a handle on the results. + * + * **JSON** - `Returning results as JSON encoded` is useful for any interactive dynamic queries. + * + * @param constant $output Either: `OBJECT`|`ARRAY_A`|`ARRAY_N`|`JSON` + * @param object|null $instance `ez_pdo`|`ez_pgsql`|`ez_sqlsrv`|`ez_sqlite3`|`ez_mysqli` + * @return bool|object|array - results as objects (default) + */ + function get_results($output = \OBJECT, $instance = null) + { + $ezQuery = empty($instance) || !is_object($instance) ? getInstance() : $instance; + return ($ezQuery instanceof ezsqlModelInterface) + ? $ezQuery->get_results(null, $output, false) + : false; + } + /** * Clear/unset the global database class instance. */ @@ -517,12 +593,12 @@ function clearInstance() } /** - * Clean input of XSS, html, javascript, etc... + * Clean input string of XSS, html, javascript, etc... * @param string $string * * @return string cleaned string */ - function cleanInput($string) + function clean_string(string $string) { return ezQuery::clean($string); } @@ -735,7 +811,37 @@ function dropping() } /** - * Set table `name` and `prefix` for global usage on calls to database + * Preforms a `alter` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Modify columns in an existing database table, by either: + *```js + * - array( column_name, datatype, ...value/options arguments ) // calls create_schema() + * - addColumn( column_name, datatype, ...value/options arguments ) // returns string + * - dropColumn( column_name ) // returns string + * - changingColumn( column_name, datatype, ...value/options arguments ) // returns string + *``` + * @param array ...$alteringSchema An array of: + * + * - @param string `$name,` - column name + * - @param string `$type,` - data type for the column + * - @param mixed `$size,` | `$value,` + * - @param mixed `...$anyOtherArgs` + * + * @return mixed results of query() call + */ + function altering(...$alteringSchema) + { + $ezQuery = getInstance(); + return ($ezQuery instanceof DatabaseInterface) + ? $ezQuery->altering(...$alteringSchema) + : false; + } + + /** + * Set table `name` and `prefix` for usage on calls to database `CRUD` * **method/function** *names* ending with `ing`. * * @param string $name @@ -751,9 +857,9 @@ function table_setup(string $name = '', string $prefix = '') } /** - * Set table `name` to use on calls to database **method/function** *names* ending with `ing`. + * Set table `name` to use on calls to database `CRUD` **method/function** *names* ending with `ing`. * - * @param string $append + * @param string $name */ function set_table(string $name = '') { @@ -765,7 +871,7 @@ function set_table(string $name = '') } /** - * Add a `prefix` to **append** to `table` name on calls to database + * Add a `prefix` to **append** to `table` name on calls to database `CRUD` * **method/function** *names* ending with `ing`. * * @param string $append diff --git a/lib/ezQuery.php b/lib/ezQuery.php index b95a21b6..51bba4b7 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -4,7 +4,7 @@ use ezsql\ezSchema; use ezsql\ezQueryInterface; -use function ezsql\functions\column; +use function ezsql\functions\{column, get_vendor}; class ezQuery implements ezQueryInterface { @@ -19,14 +19,16 @@ class ezQuery implements ezQueryInterface protected $insertId = null; /** - * The table `name` to use on calls to `selecting` method. + * The table `name` to use on calls to `ing` ending + * `CRUD` methods/functions. * * @var string */ protected $table = ''; /** - * A `prefix` to append to `table` on calls to `selecting` method. + * A `prefix` to append to `table` on calls to `ing` ending + * `CRUD` methods/functions. * * @var string */ @@ -894,7 +896,7 @@ private function create_schema(array ...$columnDataOptions) public function create(string $table = null, ...$schemas) { - $vendor = ezSchema::vendor(); + $vendor = get_vendor(); if (empty($table) || empty($schemas) || empty($vendor)) return false; @@ -955,20 +957,19 @@ public function create(string $table = null, ...$schemas) return false; } - // todo not finish, not tested - public function alter(string $table = null, ...$schemas) + public function alter(string $table = null, ...$alteringSchema) { - if (empty($table) || empty($schemas)) + if (empty($table) || empty($alteringSchema)) return false; $sql = 'ALTER TABLE ' . $table . ' '; $skipSchema = false; - if (\is_string($schemas[0])) { + if (\is_string($alteringSchema[0])) { $data = ''; $allowedTypes = ezSchema::ALTERS; $pattern = "/" . \implode('|', $allowedTypes) . "/i"; - foreach ($schemas as $types) { + foreach ($alteringSchema as $types) { if (\preg_match($pattern, $types)) { $data .= $types; $skipSchema = true; @@ -978,7 +979,7 @@ public function alter(string $table = null, ...$schemas) } if (!$skipSchema) - $schema = $this->create_schema(...$schemas); + $schema = $this->create_schema(...$alteringSchema); $alterTable = !empty($schema) ? $sql . $schema . ';' : null; if (\is_string($alterTable)) @@ -1039,8 +1040,14 @@ public function dropping() return ($table === false) ? false : $this->drop($table); } + public function altering(...$alteringSchema) + { + $table = $this->table_prefix(); + return ($table === false) ? false : $this->alter($table, ...$alteringSchema); + } + /** - * Check and return the stored **global** database `table` preset with any `prefix`. + * Check and return the stored database `table` preset with any `prefix`. * * @return boolean|string `false` if no preset. */ @@ -1049,7 +1056,7 @@ protected function table_prefix() if (empty($this->table) || !\is_string($this->table)) return $this->clearPrepare(); - $table = (!empty($this->prefix) || \is_string($this->prefix)) + $table = (!empty($this->prefix) && \is_string($this->prefix)) ? $this->prefix . $this->table : $this->table; diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 528a80b1..37abdbaf 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -749,4 +749,48 @@ public function drop(string $table = null); * @return bool|int */ public function dropping(); + + /** + * Modify columns in an existing database table, by either: + *```js + * - array( column_name, datatype, ...value/options arguments ) // calls create_schema() + * - addColumn( column_name, datatype, ...value/options arguments ) // returns string + * - dropColumn( column_name ) // returns string + * - changingColumn( column_name, datatype, ...value/options arguments ) // returns string + *``` + * @param string $table The name of the db table that you wish to alter + * @param array ...$alteringSchema An array of: + * + * - @param string `$name,` - column name + * - @param string `$type,` - data type for the column + * - @param mixed `$size,` | `$value,` + * - @param mixed `...$anyOtherArgs` + * + * @return mixed results of query() call + */ + public function alter(string $table = null, ...$alteringSchema); + + /** + * Preforms a `alter` method call on a already preset `table name`, and optional `prefix` + * + * This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)` + * to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored. + * + * Modify columns in an existing database table, by either: + *```js + * - array( column_name, datatype, ...value/options arguments ) // calls create_schema() + * - addColumn( column_name, datatype, ...value/options arguments ) // returns string + * - dropColumn( column_name ) // returns string + * - changingColumn( column_name, datatype, ...value/options arguments ) // returns string + *``` + * @param array ...$alteringSchema An array of: + * + * - @param string `$name,` - column name + * - @param string `$type,` - data type for the column + * - @param mixed `$size,` | `$value,` + * - @param mixed `...$anyOtherArgs` + * + * @return mixed results of query() call + */ + public function altering(...$alteringSchema); } diff --git a/lib/ezResultset.php b/lib/ezResultset.php index df7e5002..5a9cc1ac 100644 --- a/lib/ezResultset.php +++ b/lib/ezResultset.php @@ -49,7 +49,7 @@ class ezResultset implements \Iterator /** * Initializes the record object - * @param array $query_result The result of an ezSQL query + * @param array|object $query_result The result of an ezSQL query * @throws Exception When $query_result is not an array */ public function __construct($query_result) @@ -196,7 +196,7 @@ public function fetch_object() /** * Returns the current record as an json object and moves the internal data pointer ahead. - * @return array + * @return string */ public function fetch_json() { diff --git a/lib/ezSchema.php b/lib/ezSchema.php index 1031c5d1..6ffafb26 100644 --- a/lib/ezSchema.php +++ b/lib/ezSchema.php @@ -68,7 +68,7 @@ class ezSchema const OPTIONS = ['CONSTRAINT', 'PRIMARY KEY', 'FOREIGN KEY', 'UNIQUE', 'INDEX', 'REFERENCES']; const ALTERS = ['ADD', 'DROP COLUMN', 'CHANGE COLUMN', 'RENAME TO', 'MODIFY', 'ALTER COLUMN']; const CHANGES = [ - 'mysqli' => 'MODIFY', + 'mysqli' => 'MODIFY COLUMN', 'pgsql' => 'ALTER COLUMN', 'sqlsrv' => 'ALTER COLUMN', 'sqlite3' => '' @@ -158,14 +158,15 @@ public function __call($type, $args) } /** - * Returns the current global database vendor being used. + * Returns database vendor string, either the global instance, or provided database class. + * @param \ezsql\DatabaseInterface|null $db * * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` */ - public static function vendor() + public static function vendor(DatabaseInterface $db = null) { $type = null; - $instance = getInstance(); + $instance = empty($db) || !is_object($db) ? getInstance() : $db; if ($instance instanceof DatabaseInterface) { $type = $instance->settings()->getDriver(); if ($type === \Pdo) { diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index eaa77cf0..897c968e 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -4,80 +4,210 @@ use ezsql\ezQuery; use ezsql\ezsqlModelInterface; -use function ezsql\functions\getVendor; +use function ezsql\functions\{get_vendor, create_certificate}; /** * Core class containing common functions to manipulate **query** `result sets` once returned. * - * The class properties can be accessed with either a `set` or `get` prefix as a function. + * @method void setDebugAll($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTrace($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDebugCalled($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setVarDumpCalled($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setShowErrors($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setNumQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setConnQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCapturedErrors($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheDir($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setUseDiskCache($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheTimeout($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheInserts($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setNumRows($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDbConnectTime($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setSqlLogFile($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setProfileTimes($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setInsertId($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastQuery($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastError($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setColInfo($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTimers($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTotalQueryTime($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTraceLog($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setUseTraceLog($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDoProfile($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastResult($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setFromDiskCache($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDebugEchoIsOn($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setFuncCall($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setAllFuncCalls($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTable($name); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setPrefix($append); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. * - * @method void setDebugAll($args) - * @method void setTrace($args) - * @method void setDebugCalled($args) - * @method void setVarDumpCalled($args) - * @method void setShowErrors($args) - * @method void setNumQueries($args) - * @method void setConnQueries($args) - * @method void setCapturedErrors($args) - * @method void setCacheDir($args) - * @method void setUseDiskCache($args) - * @method void setCacheTimeout($args) - * @method void setCacheQueries($args) - * @method void setCacheInserts($args) - * @method void setNumRows($args) - * @method void setDbConnectTime($args) - * @method void setSqlLogFile($args) - * @method void setProfileTimes($args) - * @method void setInsertId($args) - * @method void setLastQuery($args) - * @method void setLastError($args) - * @method void setColInfo($args) - * @method void setTimers($args) - * @method void setTotalQueryTime($args) - * @method void setTraceLog($args) - * @method void setUseTraceLog($args) - * @method void setDoProfile($args) - * @method void setLastResult($args) - * @method void setFromDiskCache($args) - * @method void setDebugEchoIsOn($args) - * @method void setFuncCall($args) - * @method void setAllFuncCalls($args) - * @method void setTable($name) - * @method void setPrefix($append) - * - * @method string getDebugAll() - * @method string getTrace() - * @method string getDebugCalled() - * @method string getVarDumpCalled() - * @method string getShowErrors() - * @method string getNumQueries() - * @method string getConnQueries() - * @method string getCapturedErrors() - * @method string getCacheDir() - * @method string getUseDiskCache() - * @method string getCacheTimeout() - * @method string getCacheQueries() - * @method string getCacheInserts() - * @method string getNumRows() - * @method string getDbConnectTime() - * @method string getSqlLogFile() - * @method string getProfileTimes() - * @method string getInsertId() - * @method string getLastQuery() - * @method string getLastError() - * @method string getColInfo() - * @method string getTimers() - * @method string getTotalQueryTime() - * @method string getTraceLog() - * @method string getUseTraceLog() - * @method string getDoProfile() - * @method string getLastResult() - * @method string getFromDiskCache() - * @method string getDebugEchoIsOn() - * @method string getFuncCall() - * @method string getAllFuncCalls() - * @method string getTable() - * @method string getPrefix() + * @method string getDebugAll(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTrace(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDebugCalled(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getVarDumpCalled(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getShowErrors(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getNumQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getConnQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCapturedErrors(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheDir(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getUseDiskCache(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheTimeout(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheInserts(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getNumRows(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDbConnectTime(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getSqlLogFile(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getProfileTimes(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getInsertId(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastQuery(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastError(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getColInfo(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTimers(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTotalQueryTime(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTraceLog(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getUseTraceLog(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDoProfile(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastResult(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getFromDiskCache(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDebugEchoIsOn(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getFuncCall(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getAllFuncCalls(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTable(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getPrefix(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. */ class ezsqlModel extends ezQuery implements ezsqlModelInterface { @@ -176,14 +306,16 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface protected $lastQuery = null; /** - * The table `name` to use on calls to `selecting` method. + * The table `name` to use on calls to `ing` ending m + * `CRUD` methods/functions. * * @var string */ protected $table = ''; /** - * A `prefix` to append to `table` name on calls to `selecting` method. + * A `prefix` to append to `table` name on calls to `ing` ending + * `CRUD` methods/functions. * * @var string */ @@ -431,9 +563,9 @@ public function get_results(string $query = null, $output = \OBJECT, bool $use_p $this->query($query, $use_prepare); } - if ($output == OBJECT) { + if ($output === \OBJECT) { return $this->lastResult; - } elseif ($output == \_JSON) { + } elseif ($output == \JSON) { return \json_encode($this->lastResult); // return as json output } elseif ($output == \ARRAY_A || $output == \ARRAY_N) { $new_array = []; @@ -723,9 +855,9 @@ public function secureSetup( string $path = '.' . \_DS ) { if (!\file_exists($path . $cert) || !\file_exists($path . $key)) { - $vendor = getVendor(); + $vendor = get_vendor(); if (($vendor != \SQLITE) || ($vendor != \MSSQL)) - $path = ezQuery::createCertificate(); + $path = create_certificate(); } elseif ($path == '.' . \_DS) { $ssl_path = \getcwd(); $path = \preg_replace('/\\\/', \_DS, $ssl_path) . \_DS; diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 7dc39ffe..578d3068 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -3,73 +3,205 @@ namespace ezsql; /** - * @method void setDebugAll($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setTrace($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setDebugCalled($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setVarDumpCalled($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setShowErrors($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setNumQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setConnQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setCapturedErrors($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setCacheDir($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setUseDiskCache($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setCacheTimeout($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setCacheQueries($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setCacheInserts($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setNumRows($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setDbConnectTime($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setSqlLogFile($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setProfileTimes($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setInsertId($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setLastQuery($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setLastError($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setColInfo($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setTimers($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setTotalQueryTime($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setTraceLog($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setUseTraceLog($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setDoProfile($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setLastResult($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setFromDiskCache($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setDebugEchoIsOn($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setFuncCall($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setAllFuncCalls($args); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setTable($name); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method void setPrefix($append); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method void setDebugAll($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTrace($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDebugCalled($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setVarDumpCalled($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setShowErrors($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setNumQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setConnQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCapturedErrors($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheDir($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setUseDiskCache($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheTimeout($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheQueries($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setCacheInserts($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setNumRows($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDbConnectTime($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setSqlLogFile($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setProfileTimes($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setInsertId($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastQuery($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastError($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setColInfo($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTimers($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTotalQueryTime($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTraceLog($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setUseTraceLog($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDoProfile($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setLastResult($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setFromDiskCache($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setDebugEchoIsOn($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setFuncCall($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setAllFuncCalls($args); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setTable($name); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method void setPrefix($append); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. * - * @method string getDebugAll(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getTrace(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getDebugCalled(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getVarDumpCalled(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getShowErrors(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getNumQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getConnQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getCapturedErrors(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getCacheDir(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getUseDiskCache(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getCacheTimeout(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getCacheQueries(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getCacheInserts(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getNumRows(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getDbConnectTime(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getSqlLogFile(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getProfileTimes(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getInsertId(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getLastQuery(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getLastError(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getColInfo(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getTimers(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getTotalQueryTime(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getTraceLog(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getUseTraceLog(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getDoProfile(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getLastResult(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getFromDiskCache(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getDebugEchoIsOn(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getFuncCall(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getAllFuncCalls(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getTable(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. - * @method string getPrefix(); A `ezsqlModel` class property that can be accessed with either a `set` or `get` prefix as a function. + * @method string getDebugAll(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTrace(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDebugCalled(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getVarDumpCalled(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getShowErrors(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getNumQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getConnQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCapturedErrors(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheDir(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getUseDiskCache(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheTimeout(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheQueries(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getCacheInserts(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getNumRows(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDbConnectTime(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getSqlLogFile(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getProfileTimes(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getInsertId(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastQuery(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastError(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getColInfo(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTimers(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTotalQueryTime(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTraceLog(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getUseTraceLog(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDoProfile(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getLastResult(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getFromDiskCache(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getDebugEchoIsOn(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getFuncCall(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getAllFuncCalls(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getTable(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. + * @method string getPrefix(); + * A `ezsqlModel` class property that can be accessed with either + * a `set` or `get` prefix as a function. */ interface ezsqlModelInterface { @@ -182,22 +314,24 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa * - if setup/active, `prepareActive()` has been called, use * prepare statements in SQL transactions. * - * `Returning results as an object` is the quickest way to get and + * **OBJECT** - `Returning results as an object` is the quickest way to get and * display results. It is also useful that you are able to put * `$object->var` syntax directly inside print statements without * having to worry about causing php parsing errors. * - * `Returning results as an associative array` is useful if you would + * **ARRAY_A** - `Returning results as an associative array` is useful if you would * like dynamic access to column names. * - * `Returning results as a numerical array` is useful if you are using + * **ARRAY_N** - `Returning results as a numerical array` is useful if you are using * completely dynamic queries with varying column names but still need * a way to get a handle on the results. * + * **JSON** - `Returning results as JSON encoded` is useful for any interactive dynamic queries. + * @param string $query - * @param OBJECT|ARRAY_A|ARRAY_N $output + * @param constant $output Either: `OBJECT`|`ARRAY_A`|`ARRAY_N`|`JSON` * @param bool $use_prepare - has prepare statements been activated - * @return bool|mixed - results as objects (default) + * @return bool|object|array - results as objects (default) */ public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false); @@ -207,7 +341,7 @@ public function get_results(string $query = null, $output = \OBJECT, bool $use_p * Returns meta information about one or all columns such as column name or type. * - If no information type is supplied then the default information type of name is used. * - If no column offset is supplied then a one dimensional array is returned with the - * information type for ‘all columns’. + * information type for all columns. * - For access to the full meta information for all columns you can use the cached * variable `$db->colInfo`, access by calling `$db->getCol_Info()` * diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index 3910b878..32c3b27c 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -8,7 +8,7 @@ setInstance, getInstance, clearInstance, - getVendor, + get_vendor, column, primary, foreign, @@ -16,6 +16,7 @@ index, addColumn, dropColumn, + changingColumn, eq, neq, ne, @@ -45,6 +46,8 @@ replacing, selecting, inserting, + altering, + get_results, table_setup, set_table, set_prefix @@ -64,7 +67,7 @@ public function testGetInstance() public function testGetVendor() { - $this->assertNull(getVendor()); + $this->assertNull(get_vendor()); } public function testColumn() @@ -101,6 +104,10 @@ public function testDropColumn() { $this->assertFalse(dropColumn('column', 'column')); } + public function testChangingColumn() + { + $this->assertFalse(changingColumn('column', 'column')); + } public function testEq() { @@ -269,6 +276,16 @@ public function testReplacing() $this->assertFalse(replacing(['data' => 'data2'])); } + public function testAltering() + { + $this->assertFalse(altering([])); + } + + public function testGet_results() + { + $this->assertFalse(get_results()); + } + public function testDropping() { $this->assertFalse(dropping()); diff --git a/tests/ezQueryTest.php b/tests/ezQueryTest.php index bad54f3c..b79833c7 100644 --- a/tests/ezQueryTest.php +++ b/tests/ezQueryTest.php @@ -9,7 +9,8 @@ eq, neq, like, - in + in, + clean_string }; class ezQueryTest extends EZTestCase @@ -26,9 +27,9 @@ protected function tearDown(): void $this->object = null; } - public function testClean() + public function testClean_string() { - $this->assertEquals("' help", $this->object->clean("' help")); + $this->assertEquals("' help", clean_string("' help")); } public function testHaving() diff --git a/tests/ezSchemaTest.php b/tests/ezSchemaTest.php index 1f72075c..185be602 100644 --- a/tests/ezSchemaTest.php +++ b/tests/ezSchemaTest.php @@ -11,7 +11,7 @@ mssqlInstance, sqliteInstance, clearInstance, - getVendor, + get_vendor, column, primary, index @@ -22,7 +22,7 @@ class ezSchemaTest extends EZTestCase public function testVendor() { clearInstance(); - $this->assertEquals(null, getVendor()); + $this->assertEquals(null, get_vendor()); $this->assertEquals(false, ezSchema::datatype(BLOB, NULLS)); $this->assertFalse(column('id', INTR, 32, AUTO, PRIMARY)); } @@ -36,7 +36,7 @@ public function testVendor_mysqli() } mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); - $this->assertEquals(MYSQLI, getVendor()); + $this->assertEquals(MYSQLI, get_vendor()); $this->assertEquals('BLOB NULL', ezSchema::datatype(BLOB, NULLS)); $this->assertEquals('VARCHAR(256) NOT NULL', ezSchema::datatype(VARCHAR, 256, notNULL)); $this->assertEquals('id INT(32) AUTO_INCREMENT PRIMARY KEY, ', column('id', INTR, 32, AUTO, PRIMARY)); @@ -129,7 +129,7 @@ public function testVendor_Pgsql() } pgsqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]); - $this->assertEquals(PGSQL, getVendor()); + $this->assertEquals(PGSQL, get_vendor()); $this->assertEquals('TIMESTAMP NOT NULL', ezSchema::datatype(TIMESTAMP, notNULL)); $this->assertEquals('price NUMERIC(6,2) NULL, ', column('price', NUMERIC, 6, 2, NULLS)); $this->assertEquals('id SERIAL PRIMARY KEY, ', column('id', AUTO, PRIMARY)); @@ -144,7 +144,7 @@ public function testVendor_Sqlite3() } sqliteInstance([self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]); - $this->assertEquals(SQLITE3, getVendor()); + $this->assertEquals(SQLITE3, get_vendor()); } public function testVendor_Sqlsrv() @@ -156,7 +156,7 @@ public function testVendor_Sqlsrv() } mssqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); - $this->assertEquals(MSSQL, getVendor()); + $this->assertEquals(MSSQL, get_vendor()); } public function testVendor_Pdo() @@ -169,7 +169,7 @@ public function testVendor_Pdo() $pdo_mysql = pdoInstance(['mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=3306', self::TEST_DB_USER, self::TEST_DB_PASSWORD]); $pdo_mysql->connect(); - $this->assertEquals(MYSQLI, getVendor()); + $this->assertEquals(MYSQLI, get_vendor()); } public function test__construct() diff --git a/tests/ezsqlModelTest.php b/tests/ezsqlModelTest.php index c41a46d1..e8aa1391 100644 --- a/tests/ezsqlModelTest.php +++ b/tests/ezsqlModelTest.php @@ -126,7 +126,7 @@ public function testGet_results() public function testGet_col_info() { $this->assertEmpty($this->object->get_col_info()); - $this->object->setCol_Info([]); + $this->object->setColInfo([]); $this->assertNull($this->object->get_col_info()); $this->assertNull($this->object->get_col_info('name', 1)); } @@ -134,10 +134,10 @@ public function testGet_col_info() public function testStore_cache() { $sql = 'SELECT * FROM ez_test'; - $this->object->setCache_Timeout(1); - $this->object->setUse_Disk_Cache(true); - $this->object->setCache_Queries(true); - $this->object->setNum_Rows(5); + $this->object->setCacheTimeout(1); + $this->object->setUseDiskCache(true); + $this->object->setCacheQueries(true); + $this->object->setNumRows(5); $this->object->store_cache($sql, false); $this->assertEquals(5, $this->object->get_cache($sql)); @@ -160,10 +160,10 @@ public function testGet_cache() */ public function testVarDump() { - $this->object->setDebug_Echo_Is_On(false); + $this->object->debugOff(); $this->object->setLastResult(['test 1']); $this->assertNotEmpty($this->object->varDump($this->object->getLast_Result())); - $this->object->setDebug_Echo_Is_On(true); + $this->object->debugOn(); $this->expectOutputRegex('/[Last Function Call]/'); $this->object->varDump(''); } diff --git a/tests/mysqli/ezResultsetTest.php b/tests/mysqli/ezResultsetTest.php index 91dc7fe3..240c4f4a 100644 --- a/tests/mysqli/ezResultsetTest.php +++ b/tests/mysqli/ezResultsetTest.php @@ -7,7 +7,13 @@ use function ezsql\functions\{ mysqlInstance, - column + column, + get_results, + selecting, + inserting, + set_table, + creating, + dropping }; class ezResultsetTest extends EZTestCase @@ -19,7 +25,7 @@ class ezResultsetTest extends EZTestCase /** * database connection - * @var object + * @var ezsql\Database\ez_mysqli */ protected $database = null; @@ -35,22 +41,20 @@ protected function setUp(): void $this->database = mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); - $this->database->drop('unit_test'); - $this->database->create( - 'unit_test', + set_table('unit_test'); + dropping(); + creating( column('id', INTR, 11, PRIMARY), column('test_key', VARCHAR, 50) ); - - $this->database->insert('unit_test', ['id' => 1, 'test_key' => 'test 1']); - $this->database->insert('unit_test', ['id' => 2, 'test_key' => 'test 2']); - $this->database->insert('unit_test', ['id' => 3, 'test_key' => 'test 3']); - $this->database->insert('unit_test', ['id' => 4, 'test_key' => 'test 4']); - $this->database->insert('unit_test', ['id' => 5, 'test_key' => 'test 5']); - - $this->database->select('unit_test'); - - $this->object = new ezResultset($this->database->get_results()); + inserting(['id' => 1, 'test_key' => 'test 1']); + inserting(['id' => 2, 'test_key' => 'test 2']); + inserting(['id' => 3, 'test_key' => 'test 3']); + inserting(['id' => 4, 'test_key' => 'test 4']); + inserting(['id' => 5, 'test_key' => 'test 5']); + selecting(); + + $this->object = new ezResultset(get_results()); } // setUp /** @@ -146,6 +150,17 @@ public function testFetch_object() $this->assertEquals(1, $result->id); } + public function testFetch_json() + { + $result = $this->object->fetch_json(); + $json = \json_decode($result); + + $this->assertTrue((json_last_error() === \JSON_ERROR_NONE)); + $this->assertTrue(is_a($json, 'stdClass')); + + $this->assertEquals(1, $json->id); + } + public function test__Construct() { $resultset = $this->getMockBuilder(ezResultset::class) diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index ef6e0dd6..534f7ef4 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -10,12 +10,22 @@ use function ezsql\functions\{ mysqlInstance, column, + addColumn, + dropColumn, primary, eq, like, between, + create_select, selecting, inserting, + set_table, + set_prefix, + creating, + dropping, + altering, + get_results, + replacing, table_setup, where }; @@ -105,6 +115,7 @@ public function testDbSelect() $this->errors = array(); $this->assertTrue($this->object->dbSelect('')); $this->object->disconnect(); + set_error_handler(array($this, 'errorHandler')); $this->assertFalse($this->object->dbSelect('notest')); $this->object->connect(); $this->object->reset(); @@ -176,7 +187,7 @@ public function testGet_results() $this->assertEquals($this->object->query('INSERT INTO unit_test(id, test_key) VALUES(3, \'test 3\')'), 1); $this->object->query('SELECT * FROM unit_test'); - $result = $this->object->get_results('SELECT * FROM unit_test', _JSON); + $result = $this->object->get_results('SELECT * FROM unit_test', JSON); $this->assertEquals('[{"id":"1","test_key":"test 1"},{"id":"2","test_key":"test 2"},{"id":"3","test_key":"test 3"}]', $result); } @@ -273,10 +284,10 @@ public function testCreatingReplacing() $this->assertFalse($this->object->replacing([])); $this->assertFalse($this->object->creating([])); - table_setup('unit_test'); + set_table('unit_test'); $this->assertEquals( 0, - $this->object->creating( + creating( column('id', INTR, 11, AUTO, PRIMARY), column('test_key', VARCHAR, 50) ) @@ -285,7 +296,7 @@ public function testCreatingReplacing() inserting(array('test_key' => 'test 1')); inserting(array('test_key' => 'test 2')); inserting(array('test_key' => 'test 3')); - $this->assertEquals(3, $this->object->replacing(array('id' => 3, 'test_key' => 'test 4'))); + $this->assertEquals(3, replacing(array('id' => 3, 'test_key' => 'test 4'))); } public function testUpdate() @@ -427,6 +438,55 @@ public function testSelectingInserting() } } + public function testAltering() + { + $this->object->connect(); + set_table('test'); + set_prefix('unit_'); + creating( + column('id', INTR, 11, PRIMARY), + column('test_key', VARCHAR, 50) + ); + + $results = null; + $results = altering( + addColumn('add_key', VARCHAR, 50) + ); + $this->assertEquals(0, $results); + + inserting(array('id' => 1, 'test_key' => 'testing 1', 'add_key' => 'adding 1')); + inserting(array('id' => 2, 'test_key' => 'testing 2', 'add_key' => 'adding 2')); + inserting(array('id' => 3, 'test_key' => 'testing 3', 'add_key' => 'adding 3')); + + $result = selecting(); + + $i = 1; + foreach ($result as $row) { + $this->assertEquals($i, $row->id); + $this->assertEquals('testing ' . $i, $row->test_key); + $this->assertEquals('adding ' . $i, $row->add_key); + ++$i; + } + + $results = null; + $results = altering( + dropColumn('test_key') + ); + $this->assertEquals(0, $results); + + selecting(); + + $i = 1; + foreach (get_results() as $row) { + $this->assertEquals($i, $row->id); + $this->assertNotEquals('testing ' . $i, $row->test_key); + $this->assertEquals('adding ' . $i, $row->add_key); + ++$i; + } + + dropping(); + } + public function testBeginTransactionCommit() { $this->object->connect(); @@ -545,7 +605,7 @@ public function testSelectAndCreateTable() $result = $this->object->select('users', 'id, tel_num, email', eq('user_name ', 'walker')); - $this->object->setDebugEchoIsOn(true); + $this->object->debugOn(); $this->expectOutputRegex('/[123456]/'); $this->expectOutputRegex('/[walker@email.com]/'); $this->object->debug(); @@ -569,7 +629,7 @@ public function testCreate_select() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); - $this->assertEquals(0, $this->object->create_select('new_new_test', '*', 'unit_test')); + $this->assertEquals(0, create_select('new_new_test', '*', 'unit_test')); $result = $this->object->select('new_new_test'); diff --git a/tests/postgresql/postgresqlTest.php b/tests/postgresql/postgresqlTest.php index 2eafff38..c030c716 100644 --- a/tests/postgresql/postgresqlTest.php +++ b/tests/postgresql/postgresqlTest.php @@ -8,6 +8,10 @@ use function ezsql\functions\{ column, + creating, + deleting, + dropping, + updating, primary, eq, pgsqlInstance, @@ -83,7 +87,7 @@ public function testEscape() $this->assertEquals("This is''nt escaped.", $result); } - public function testSysdate() + public function testSysDate() { $this->assertEquals('NOW()', $this->object->sysDate()); } @@ -195,7 +199,7 @@ public function testUpdatingDeleting() table_setup('unit_test'); $this->assertEquals( 0, - $this->object->creating( + creating( column('id', AUTO, PRIMARY), column('test_key', VARCHAR, 50), column('test_value', VARCHAR, 50) @@ -209,15 +213,15 @@ public function testUpdatingDeleting() $this->assertEquals($result, 3); $unit_test['test_key'] = 'the key string'; - $this->assertEquals(1, $this->object->updating($unit_test, eq('test_key', 'test 1'))); - $this->assertEquals(1, $this->object->deleting(eq('test_key', 'test 3'))); + $this->assertEquals(1, updating($unit_test, eq('test_key', 'test 1'))); + $this->assertEquals(1, deleting(eq('test_key', 'test 3'))); $result = selecting('test_value', eq('test_key', 'the key string')); foreach ($result as $row) { $this->assertEquals('testing string 1', $row->test_value); } - $this->object->drop('unit_test'); + dropping(); } public function testDelete()