4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Caster;
14 use Symfony\Component\VarDumper\Cloner\Stub;
17 * Casts pqsql resources to array representation.
19 * @author Nicolas Grekas <p@tchwork.com>
23 private static $paramCodes = array(
27 'session_authorization',
33 'standard_conforming_strings',
36 private static $transactionStatus = array(
37 PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE',
38 PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE',
39 PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS',
40 PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR',
41 PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN',
44 private static $resultStatus = array(
45 PGSQL_EMPTY_QUERY => 'PGSQL_EMPTY_QUERY',
46 PGSQL_COMMAND_OK => 'PGSQL_COMMAND_OK',
47 PGSQL_TUPLES_OK => 'PGSQL_TUPLES_OK',
48 PGSQL_COPY_OUT => 'PGSQL_COPY_OUT',
49 PGSQL_COPY_IN => 'PGSQL_COPY_IN',
50 PGSQL_BAD_RESPONSE => 'PGSQL_BAD_RESPONSE',
51 PGSQL_NONFATAL_ERROR => 'PGSQL_NONFATAL_ERROR',
52 PGSQL_FATAL_ERROR => 'PGSQL_FATAL_ERROR',
55 private static $diagCodes = array(
56 'severity' => PGSQL_DIAG_SEVERITY,
57 'sqlstate' => PGSQL_DIAG_SQLSTATE,
58 'message' => PGSQL_DIAG_MESSAGE_PRIMARY,
59 'detail' => PGSQL_DIAG_MESSAGE_DETAIL,
60 'hint' => PGSQL_DIAG_MESSAGE_HINT,
61 'statement position' => PGSQL_DIAG_STATEMENT_POSITION,
62 'internal position' => PGSQL_DIAG_INTERNAL_POSITION,
63 'internal query' => PGSQL_DIAG_INTERNAL_QUERY,
64 'context' => PGSQL_DIAG_CONTEXT,
65 'file' => PGSQL_DIAG_SOURCE_FILE,
66 'line' => PGSQL_DIAG_SOURCE_LINE,
67 'function' => PGSQL_DIAG_SOURCE_FUNCTION,
70 public static function castLargeObject($lo, array $a, Stub $stub, $isNested)
72 $a['seek position'] = pg_lo_tell($lo);
77 public static function castLink($link, array $a, Stub $stub, $isNested)
79 $a['status'] = pg_connection_status($link);
80 $a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
81 $a['busy'] = pg_connection_busy($link);
83 $a['transaction'] = pg_transaction_status($link);
84 if (isset(self::$transactionStatus[$a['transaction']])) {
85 $a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
88 $a['pid'] = pg_get_pid($link);
89 $a['last error'] = pg_last_error($link);
90 $a['last notice'] = pg_last_notice($link);
91 $a['host'] = pg_host($link);
92 $a['port'] = pg_port($link);
93 $a['dbname'] = pg_dbname($link);
94 $a['options'] = pg_options($link);
95 $a['version'] = pg_version($link);
97 foreach (self::$paramCodes as $v) {
98 if (false !== $s = pg_parameter_status($link, $v)) {
103 $a['param']['client_encoding'] = pg_client_encoding($link);
104 $a['param'] = new EnumStub($a['param']);
109 public static function castResult($result, array $a, Stub $stub, $isNested)
111 $a['num rows'] = pg_num_rows($result);
112 $a['status'] = pg_result_status($result);
113 if (isset(self::$resultStatus[$a['status']])) {
114 $a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']);
116 $a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING);
118 if (-1 === $a['num rows']) {
119 foreach (self::$diagCodes as $k => $v) {
120 $a['error'][$k] = pg_result_error_field($result, $v);
124 $a['affected rows'] = pg_affected_rows($result);
125 $a['last OID'] = pg_last_oid($result);
127 $fields = pg_num_fields($result);
129 for ($i = 0; $i < $fields; ++$i) {
131 'name' => pg_field_name($result, $i),
132 'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)),
133 'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)),
134 'nullable' => (bool) pg_field_is_null($result, $i),
135 'storage' => pg_field_size($result, $i).' bytes',
136 'display' => pg_field_prtlen($result, $i).' chars',
138 if (' (OID: )' === $field['table']) {
139 $field['table'] = null;
141 if ('-1 bytes' === $field['storage']) {
142 $field['storage'] = 'variable size';
143 } elseif ('1 bytes' === $field['storage']) {
144 $field['storage'] = '1 byte';
146 if ('1 chars' === $field['display']) {
147 $field['display'] = '1 char';
149 $a['fields'][] = new EnumStub($field);