Skip to content

Commit 9fd73b6

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 409c7ff + 5ddb326 commit 9fd73b6

File tree

10 files changed

+167
-86
lines changed

10 files changed

+167
-86
lines changed

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/.github export-ignore
12
/.gitattributes export-ignore
23
/.gitignore export-ignore
3-
/.gitmodules export-ignore
44
/.travis.yml export-ignore
55
/phpunit.xml export-ignore
66
/tests export-ignore
7+
/tools export-ignore
8+
/Makefile export-ignore

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
test:
11+
name: Test
12+
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
php-version: [
18+
'5.3', '5.4', '5.5', '5.6',
19+
'7.0', '7.1', '7.2', '7.3', '7.4',
20+
'8.0', '8.1'
21+
]
22+
23+
steps:
24+
- name: Setup PHP ${{ matrix.php-version }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-version }}
28+
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
- name: Install dependencies
33+
run: composer install --quiet --no-ansi --prefer-dist --no-progress --no-interaction
34+
35+
- name: Run test suite
36+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
37+
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v1
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
42+
file: ./coverage.xml
43+
fail_ci_if_error: true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-2021 Norifumi SUNAOKA
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SOURCE := https://raw.githubusercontent.com/postgres/postgres/master/src/backend/utils/errcodes.txt
2+
TARGET := $(CURDIR)/src/PostgresError.php
3+
GENERATOR := php $(CURDIR)/tools/generator.php
4+
5+
all: clean $(TARGET)
6+
7+
$(TARGET):
8+
curl -s $(SOURCE) | $(GENERATOR) > $@
9+
10+
clean:
11+
-$(RM) $(TARGET)
12+
13+
.PHONY: all clean

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# PostgreSQL Error Codes for PHP
22

3+
[![License](https://poser.pugx.org/sunaoka/php-postgresql-errors/license)](https://packagist.org/packages/sunaoka/php-postgresql-errors)
4+
[![PHP](https://img.shields.io/packagist/php-v/sunaoka/php-postgresql-errors)](composer.json)
5+
[![Test](https://github.com/sunaoka/php-postgresql-errors/actions/workflows/test.yml/badge.svg)](https://github.com/sunaoka/php-postgresql-errors/actions/workflows/test.yml)
6+
[![codecov](https://codecov.io/gh/sunaoka/php-postgresql-errors/branch/develop/graph/badge.svg)](https://codecov.io/gh/sunaoka/php-postgresql-errors)
7+
8+
----
9+
310
## Installation
411

512
```bash

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
"email": "[email protected]"
1111
}
1212
],
13+
"require": {
14+
"php": "^5.3 || ^7.0 || ^8.0"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.2 || ^9.3"
18+
},
1319
"autoload": {
1420
"psr-4": {
1521
"Sunaoka\\PostgresError\\": "src/"
1622
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"Sunaoka\\PostgresError\\Tests\\": "tests/"
27+
}
1728
}
1829
}

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
beStrictAboutTestsThatDoNotTestAnything="false"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnError="false"
12+
stopOnFailure="false"
13+
verbose="true"
14+
>
15+
<testsuites>
16+
<testsuite name="test">
17+
<directory suffix="Test.php">./tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/PostgresError.php

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
class PostgresError
66
{
7-
// Class 00 — Successful Completion
87
const SUCCESSFUL_COMPLETION = '00000';
9-
10-
// Class 01 — Warning
118
const WARNING = '01000';
129
const DYNAMIC_RESULT_SETS_RETURNED = '0100C';
1310
const IMPLICIT_ZERO_BIT_PADDING = '01008';
@@ -16,54 +13,28 @@ class PostgresError
1613
const PRIVILEGE_NOT_REVOKED = '01006';
1714
const STRING_DATA_RIGHT_TRUNCATION = '01004';
1815
const DEPRECATED_FEATURE = '01P01';
19-
20-
// Class 02 — No Data (this is also a warning class per the SQL standard)
2116
const NO_DATA = '02000';
2217
const NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED = '02001';
23-
24-
// Class 03 — SQL Statement Not Yet Complete
2518
const SQL_STATEMENT_NOT_YET_COMPLETE = '03000';
26-
27-
// Class 08 — Connection Exception
2819
const CONNECTION_EXCEPTION = '08000';
2920
const CONNECTION_DOES_NOT_EXIST = '08003';
3021
const CONNECTION_FAILURE = '08006';
3122
const SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION = '08001';
3223
const SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION = '08004';
3324
const TRANSACTION_RESOLUTION_UNKNOWN = '08007';
3425
const PROTOCOL_VIOLATION = '08P01';
35-
36-
// Class 09 — Triggered Action Exception
3726
const TRIGGERED_ACTION_EXCEPTION = '09000';
38-
39-
// Class 0A — Feature Not Supported
4027
const FEATURE_NOT_SUPPORTED = '0A000';
41-
42-
// Class 0B — Invalid Transaction Initiation
4328
const INVALID_TRANSACTION_INITIATION = '0B000';
44-
45-
// Class 0F — Locator Exception
4629
const LOCATOR_EXCEPTION = '0F000';
4730
const INVALID_LOCATOR_SPECIFICATION = '0F001';
48-
49-
// Class 0L — Invalid Grantor
5031
const INVALID_GRANTOR = '0L000';
5132
const INVALID_GRANT_OPERATION = '0LP01';
52-
53-
// Class 0P — Invalid Role Specification
5433
const INVALID_ROLE_SPECIFICATION = '0P000';
55-
56-
// Class 0Z — Diagnostics Exception
5734
const DIAGNOSTICS_EXCEPTION = '0Z000';
5835
const STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER = '0Z002';
59-
60-
// Class 20 — Case Not Found
6136
const CASE_NOT_FOUND = '20000';
62-
63-
// Class 21 — Cardinality Violation
6437
const CARDINALITY_VIOLATION = '21000';
65-
66-
// Class 22 — Data Exception
6738
const DATA_EXCEPTION = '22000';
6839
const ARRAY_SUBSCRIPT_ERROR = '2202E';
6940
const CHARACTER_NOT_IN_REPERTOIRE = '22021';
@@ -131,20 +102,14 @@ class PostgresError
131102
const TOO_MANY_JSON_ARRAY_ELEMENTS = '2203D';
132103
const TOO_MANY_JSON_OBJECT_MEMBERS = '2203E';
133104
const SQL_JSON_SCALAR_REQUIRED = '2203F';
134-
135-
// Class 23 — Integrity Constraint Violation
136105
const INTEGRITY_CONSTRAINT_VIOLATION = '23000';
137106
const RESTRICT_VIOLATION = '23001';
138107
const NOT_NULL_VIOLATION = '23502';
139108
const FOREIGN_KEY_VIOLATION = '23503';
140109
const UNIQUE_VIOLATION = '23505';
141110
const CHECK_VIOLATION = '23514';
142111
const EXCLUSION_VIOLATION = '23P01';
143-
144-
// Class 24 — Invalid Cursor State
145112
const INVALID_CURSOR_STATE = '24000';
146-
147-
// Class 25 — Invalid Transaction State
148113
const INVALID_TRANSACTION_STATE = '25000';
149114
const ACTIVE_SQL_TRANSACTION = '25001';
150115
const BRANCH_TRANSACTION_ALREADY_ACTIVE = '25002';
@@ -157,67 +122,39 @@ class PostgresError
157122
const NO_ACTIVE_SQL_TRANSACTION = '25P01';
158123
const IN_FAILED_SQL_TRANSACTION = '25P02';
159124
const IDLE_IN_TRANSACTION_SESSION_TIMEOUT = '25P03';
160-
161-
// Class 26 — Invalid SQL Statement Name
162125
const INVALID_SQL_STATEMENT_NAME = '26000';
163-
164-
// Class 27 — Triggered Data Change Violation
165126
const TRIGGERED_DATA_CHANGE_VIOLATION = '27000';
166-
167-
// Class 28 — Invalid Authorization Specification
168127
const INVALID_AUTHORIZATION_SPECIFICATION = '28000';
169128
const INVALID_PASSWORD = '28P01';
170-
171-
// Class 2B — Dependent Privilege Descriptors Still Exist
172129
const DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST = '2B000';
173130
const DEPENDENT_OBJECTS_STILL_EXIST = '2BP01';
174-
175-
// Class 2D — Invalid Transaction Termination
176131
const INVALID_TRANSACTION_TERMINATION = '2D000';
177-
178-
// Class 2F — SQL Routine Exception
179132
const SQL_ROUTINE_EXCEPTION = '2F000';
180133
const FUNCTION_EXECUTED_NO_RETURN_STATEMENT = '2F005';
181134
const MODIFYING_SQL_DATA_NOT_PERMITTED = '2F002';
182135
const PROHIBITED_SQL_STATEMENT_ATTEMPTED = '2F003';
183136
const READING_SQL_DATA_NOT_PERMITTED = '2F004';
184-
185-
// Class 34 — Invalid Cursor Name
186137
const INVALID_CURSOR_NAME = '34000';
187-
188-
// Class 38 — External Routine Exception
189138
const EXTERNAL_ROUTINE_EXCEPTION = '38000';
190139
const CONTAINING_SQL_NOT_PERMITTED = '38001';
191140
const MODIFYING_SQL_DATA_NOT_PERMITTED_EXCEPTION = '38002';
192141
const PROHIBITED_SQL_STATEMENT_ATTEMPTED_EXCEPTION = '38003';
193142
const READING_SQL_DATA_NOT_PERMITTED_EXCEPTION = '38004';
194-
195-
// Class 39 — External Routine Invocation Exception
196143
const EXTERNAL_ROUTINE_INVOCATION_EXCEPTION = '39000';
197144
const INVALID_SQLSTATE_RETURNED = '39001';
198145
const NULL_VALUE_NOT_ALLOWED_EXCEPTION = '39004';
199146
const TRIGGER_PROTOCOL_VIOLATED = '39P01';
200147
const SRF_PROTOCOL_VIOLATED = '39P02';
201148
const EVENT_TRIGGER_PROTOCOL_VIOLATED = '39P03';
202-
203-
// Class 3B — Savepoint Exception
204149
const SAVEPOINT_EXCEPTION = '3B000';
205150
const INVALID_SAVEPOINT_SPECIFICATION = '3B001';
206-
207-
// Class 3D — Invalid Catalog Name
208151
const INVALID_CATALOG_NAME = '3D000';
209-
210-
// Class 3F — Invalid Schema Name
211152
const INVALID_SCHEMA_NAME = '3F000';
212-
213-
// Class 40 — Transaction Rollback
214153
const TRANSACTION_ROLLBACK = '40000';
215154
const TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION = '40002';
216155
const SERIALIZATION_FAILURE = '40001';
217156
const STATEMENT_COMPLETION_UNKNOWN = '40003';
218157
const DEADLOCK_DETECTED = '40P01';
219-
220-
// Class 42 — Syntax Error or Access Rule Violation
221158
const SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION = '42000';
222159
const SYNTAX_ERROR = '42601';
223160
const INSUFFICIENT_PRIVILEGE = '42501';
@@ -262,52 +199,35 @@ class PostgresError
262199
const INVALID_SCHEMA_DEFINITION = '42P15';
263200
const INVALID_TABLE_DEFINITION = '42P16';
264201
const INVALID_OBJECT_DEFINITION = '42P17';
265-
266-
// Class 44 — WITH CHECK OPTION Violation
267202
const WITH_CHECK_OPTION_VIOLATION = '44000';
268-
269-
// Class 53 — Insufficient Resources
270203
const INSUFFICIENT_RESOURCES = '53000';
271204
const DISK_FULL = '53100';
272205
const OUT_OF_MEMORY = '53200';
273206
const TOO_MANY_CONNECTIONS = '53300';
274207
const CONFIGURATION_LIMIT_EXCEEDED = '53400';
275-
276-
// Class 54 — Program Limit Exceeded
277208
const PROGRAM_LIMIT_EXCEEDED = '54000';
278209
const STATEMENT_TOO_COMPLEX = '54001';
279210
const TOO_MANY_COLUMNS = '54011';
280211
const TOO_MANY_ARGUMENTS = '54023';
281-
282-
// Class 55 — Object Not In Prerequisite State
283212
const OBJECT_NOT_IN_PREREQUISITE_STATE = '55000';
284213
const OBJECT_IN_USE = '55006';
285214
const CANT_CHANGE_RUNTIME_PARAM = '55P02';
286215
const LOCK_NOT_AVAILABLE = '55P03';
287216
const UNSAFE_NEW_ENUM_VALUE_USAGE = '55P04';
288-
289-
// Class 57 — Operator Intervention
290217
const OPERATOR_INTERVENTION = '57000';
291218
const QUERY_CANCELED = '57014';
292219
const ADMIN_SHUTDOWN = '57P01';
293220
const CRASH_SHUTDOWN = '57P02';
294221
const CANNOT_CONNECT_NOW = '57P03';
295222
const DATABASE_DROPPED = '57P04';
296-
297-
// Class 58 — System Error (errors external to PostgreSQL itself)
223+
const IDLE_SESSION_TIMEOUT = '57P05';
298224
const SYSTEM_ERROR = '58000';
299225
const IO_ERROR = '58030';
300226
const UNDEFINED_FILE = '58P01';
301227
const DUPLICATE_FILE = '58P02';
302-
303-
// Class 72 — Snapshot Failure
304228
const SNAPSHOT_TOO_OLD = '72000';
305-
306-
// Class F0 — Configuration File Error
307229
const CONFIG_FILE_ERROR = 'F0000';
308230
const LOCK_FILE_EXISTS = 'F0001';
309-
310-
// Class HV — Foreign Data Wrapper Error (SQL/MED)
311231
const FDW_ERROR = 'HV000';
312232
const FDW_COLUMN_NAME_NOT_FOUND = 'HV005';
313233
const FDW_DYNAMIC_PARAMETER_VALUE_NEEDED = 'HV002';
@@ -335,15 +255,11 @@ class PostgresError
335255
const FDW_UNABLE_TO_CREATE_EXECUTION = 'HV00L';
336256
const FDW_UNABLE_TO_CREATE_REPLY = 'HV00M';
337257
const FDW_UNABLE_TO_ESTABLISH_CONNECTION = 'HV00N';
338-
339-
// Class P0 — PL/pgSQL Error
340258
const PLPGSQL_ERROR = 'P0000';
341259
const RAISE_EXCEPTION = 'P0001';
342260
const NO_DATA_FOUND = 'P0002';
343261
const TOO_MANY_ROWS = 'P0003';
344262
const ASSERT_FAILURE = 'P0004';
345-
346-
// Class XX — Internal Error
347263
const INTERNAL_ERROR = 'XX000';
348264
const DATA_CORRUPTED = 'XX001';
349265
const INDEX_CORRUPTED = 'XX002';

tests/PostgresErrorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Sunaoka\PostgresError\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Sunaoka\PostgresError\PostgresError;
7+
8+
class PostgresErrorTest extends TestCase
9+
{
10+
public function test()
11+
{
12+
self::assertSame('00000', PostgresError::SUCCESSFUL_COMPLETION);
13+
}
14+
}

0 commit comments

Comments
 (0)