1 | <?php |
||
11 | class PostgresqlStore extends AbstractStore |
||
12 | { |
||
13 | /** |
||
14 | * @var string The name of the table to store the data into. |
||
15 | */ |
||
16 | private $tableName; |
||
17 | |||
18 | /** |
||
19 | * @var string The name of the primary key column in the table the data is being stored in. |
||
20 | */ |
||
21 | private $primaryKey; |
||
22 | |||
23 | /** |
||
24 | * @var array Data type and format metadata for each column being inserted. |
||
25 | * The Key is the CSV column position in the file and value is an array of: |
||
26 | * "pdo_type" - The PDO data type |
||
27 | * "type" - The schema data type |
||
28 | * "format" - The schema format. |
||
29 | */ |
||
30 | private $column_metadata = []; |
||
31 | |||
32 | /** |
||
33 | * @var string The CSV list of columns to be inserted into. |
||
34 | */ |
||
35 | private $columnList; |
||
36 | |||
37 | /** |
||
38 | * @var string The parameters to be used in the insert statement. |
||
39 | */ |
||
40 | private $insertParameters; |
||
41 | |||
42 | /** |
||
43 | * @var int The current CSV row being stored. |
||
44 | */ |
||
45 | private $currentCsvRow; |
||
46 | |||
47 | /** |
||
48 | * @var int The position of the current CSV row row in the CSV file. |
||
49 | */ |
||
50 | private $rowNumber; |
||
51 | |||
52 | /** |
||
53 | * @var int The position of the current CSV field in the current row. |
||
54 | */ |
||
55 | private $fieldNumber; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * @static |
||
60 | * |
||
61 | * @var array Mappings of JSON table types to PDO param types. |
||
62 | */ |
||
63 | private static $pdo_type_mappings = [ |
||
64 | 'any' => \PDO::PARAM_STR, |
||
65 | 'array' => \PDO::PARAM_STR, |
||
66 | 'boolean' => \PDO::PARAM_BOOL, |
||
67 | 'date' => \PDO::PARAM_STR, |
||
68 | 'datetime' => \PDO::PARAM_STR, |
||
69 | 'time' => \PDO::PARAM_STR, |
||
70 | 'integer' => \PDO::PARAM_INT, |
||
71 | 'null' => \PDO::PARAM_NULL, |
||
72 | 'number' => \PDO::PARAM_STR, |
||
73 | 'string' => \PDO::PARAM_STR |
||
74 | ]; |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Store the data. |
||
79 | * |
||
80 | * @param string $tableName The name of the table to save the data in. With optional schema prefix. |
||
81 | * @param string $primaryKey The name of the primary key on the table. [optional] The default is "id". |
||
82 | * The primary key does not need to be listed in the CSV if it has |
||
83 | * a serial associated with it. |
||
84 | * |
||
85 | * @return boolean true |
||
86 | */ |
||
87 | public function store($tableName, $primaryKey = 'id') |
||
101 | |||
102 | |||
103 | /** |
||
104 | * Get the PDO type, schema type & schema format for each column in the CSV file. |
||
105 | * |
||
106 | * @return boolean true on success |
||
107 | */ |
||
108 | private function setColumnsMetadata() |
||
126 | |||
127 | |||
128 | /** |
||
129 | * Set the columns that will be inserted into. |
||
130 | * The columns include the "csv_row" field to store the CSV row |
||
131 | * number to help make error messages more useful. |
||
132 | * |
||
133 | * @return void |
||
134 | */ |
||
135 | private function setColumns() |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Set the insert parameters string. |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | private function setInsertParameters() |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Store each of the CSV rows. |
||
156 | * |
||
157 | * @return void |
||
158 | * |
||
159 | * @throws \Exception if the row couldn't be inserted into the database. |
||
160 | */ |
||
161 | private function storeCsvRows() |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Do any data manipulation required on the specified column's value. |
||
197 | * |
||
198 | * @param array $columnMetadata The metadata about the column. |
||
199 | * @param string $fieldValue The value to update. |
||
200 | * |
||
201 | * @return string The updated field value. |
||
202 | */ |
||
203 | private function updateFieldValue($columnMetadata, $fieldValue) |
||
219 | } |
||
220 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..