@@ -28,8 +28,9 @@ |
||
| 28 | 28 | |
| 29 | 29 | protected function getExplainSyntax() |
| 30 | 30 | { |
| 31 | - if ( $this->queryStructure->getElement( QueryStructure::EXPLAIN ) ) |
|
| 32 | - return 'EXPLAIN'; |
|
| 31 | + if ( $this->queryStructure->getElement( QueryStructure::EXPLAIN ) ) { |
|
| 32 | + return 'EXPLAIN'; |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | return ''; |
| 35 | 36 | } |
@@ -106,8 +106,9 @@ |
||
| 106 | 106 | */ |
| 107 | 107 | public function execute() |
| 108 | 108 | { |
| 109 | - if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) ) |
|
| 110 | - throw new QueryException( 'Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
| 109 | + if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) ) { |
|
| 110 | + throw new QueryException( 'Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
| 111 | + } |
|
| 111 | 112 | |
| 112 | 113 | return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
| 113 | 114 | } |
@@ -96,8 +96,9 @@ |
||
| 96 | 96 | public function execute() |
| 97 | 97 | { |
| 98 | 98 | |
| 99 | - if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) ) |
|
| 100 | - throw new QueryException( 'Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
| 99 | + if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) ) { |
|
| 100 | + throw new QueryException( 'Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
| 101 | + } |
|
| 101 | 102 | |
| 102 | 103 | return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
| 103 | 104 | |
@@ -117,8 +117,9 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $this->queryInit( $query, $params ); |
| 119 | 119 | |
| 120 | - if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) |
|
| 121 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 120 | + if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 121 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 122 | + } |
|
| 122 | 123 | |
| 123 | 124 | $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM ); |
| 124 | 125 | |
@@ -141,8 +142,9 @@ discard block |
||
| 141 | 142 | { |
| 142 | 143 | $this->queryInit( $query, $params ); |
| 143 | 144 | |
| 144 | - if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) |
|
| 145 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 145 | + if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 146 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 147 | + } |
|
| 146 | 148 | |
| 147 | 149 | $result = $this->sQuery->fetch( $fetchmode ); |
| 148 | 150 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued, |
@@ -159,8 +161,9 @@ discard block |
||
| 159 | 161 | { |
| 160 | 162 | $this->queryInit( $query, $params ); |
| 161 | 163 | |
| 162 | - if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) |
|
| 163 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 164 | + if ( $this->lastStatement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 165 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 166 | + } |
|
| 164 | 167 | |
| 165 | 168 | $result = $this->sQuery->fetchColumn(); |
| 166 | 169 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued |
@@ -242,11 +245,12 @@ discard block |
||
| 242 | 245 | |
| 243 | 246 | private function prepareParams( array $parameters ) |
| 244 | 247 | { |
| 245 | - if ( self::isArrayAssoc( $parameters ) ) |
|
| 246 | - $this->bindMore( $parameters ); |
|
| 247 | - else |
|
| 248 | - foreach ( $parameters as $key => $val ) |
|
| 248 | + if ( self::isArrayAssoc( $parameters ) ) { |
|
| 249 | + $this->bindMore( $parameters ); |
|
| 250 | + } else { |
|
| 251 | + foreach ( $parameters as $key => $val ) |
|
| 249 | 252 | $this->parameters[] = array( $key + 1, $val ); |
| 253 | + } |
|
| 250 | 254 | } |
| 251 | 255 | |
| 252 | 256 | private function pdoBindValues() |
@@ -254,14 +258,11 @@ discard block |
||
| 254 | 258 | foreach ( $this->parameters as $param => $value ) { |
| 255 | 259 | if ( is_int( $value[ 1 ] ) ) { |
| 256 | 260 | $type = \PDO::PARAM_INT; |
| 257 | - } |
|
| 258 | - elseif ( is_bool( $value[ 1 ] ) ) { |
|
| 261 | + } elseif ( is_bool( $value[ 1 ] ) ) { |
|
| 259 | 262 | $type = \PDO::PARAM_BOOL; |
| 260 | - } |
|
| 261 | - elseif ( is_null( $value[ 1 ] ) ) { |
|
| 263 | + } elseif ( is_null( $value[ 1 ] ) ) { |
|
| 262 | 264 | $type = \PDO::PARAM_NULL; |
| 263 | - } |
|
| 264 | - else { |
|
| 265 | + } else { |
|
| 265 | 266 | $type = \PDO::PARAM_STR; |
| 266 | 267 | } |
| 267 | 268 | $this->sQuery->bindValue( $value[ 0 ], $value[ 1 ], $type ); |
@@ -305,10 +306,11 @@ discard block |
||
| 305 | 306 | { |
| 306 | 307 | $queryString = trim( $queryString ); |
| 307 | 308 | |
| 308 | - if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) |
|
| 309 | - return strtoupper( $matches[ 1 ] ); |
|
| 310 | - else |
|
| 311 | - return self::QUERY_TYPE_OTHER; |
|
| 309 | + if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) { |
|
| 310 | + return strtoupper( $matches[ 1 ] ); |
|
| 311 | + } else { |
|
| 312 | + return self::QUERY_TYPE_OTHER; |
|
| 313 | + } |
|
| 312 | 314 | } |
| 313 | 315 | |
| 314 | 316 | /** |
@@ -317,8 +319,9 @@ discard block |
||
| 317 | 319 | */ |
| 318 | 320 | public static function isArrayAssoc( array $arr ) |
| 319 | 321 | { |
| 320 | - if ( array() === $arr ) |
|
| 321 | - return false; |
|
| 322 | + if ( array() === $arr ) { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 322 | 325 | |
| 323 | 326 | return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
| 324 | 327 | } |
@@ -103,10 +103,11 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | private function makeInCondition() |
| 105 | 105 | { |
| 106 | - if ( is_a( $this->temporaryParam[ 1 ], QuerySelect::class ) ) |
|
| 107 | - $this->inQuerySelect(); |
|
| 108 | - elseif ( is_array( $this->temporaryParam[ 1 ] ) ) |
|
| 109 | - $this->inArray(); |
|
| 106 | + if ( is_a( $this->temporaryParam[ 1 ], QuerySelect::class ) ) { |
|
| 107 | + $this->inQuerySelect(); |
|
| 108 | + } elseif ( is_array( $this->temporaryParam[ 1 ] ) ) { |
|
| 109 | + $this->inArray(); |
|
| 110 | + } |
|
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 | private function inQuerySelect() |
@@ -182,8 +183,9 @@ discard block |
||
| 182 | 183 | */ |
| 183 | 184 | private function getWhereAndHavingSyntax( $clauseType ) |
| 184 | 185 | { |
| 185 | - if ( count( $this->queryStructure->getElement( $clauseType ) ) == 0 ) |
|
| 186 | - return ''; |
|
| 186 | + if ( count( $this->queryStructure->getElement( $clauseType ) ) == 0 ) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 187 | 189 | |
| 188 | 190 | $where = ''; |
| 189 | 191 | $last_type = 'where_start'; |
@@ -212,11 +214,13 @@ discard block |
||
| 212 | 214 | */ |
| 213 | 215 | private function validateWhereParam( $param ) |
| 214 | 216 | { |
| 215 | - if ( count( $param ) < 2 ) |
|
| 216 | - throw new QueryException( 'Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
|
| 217 | + if ( count( $param ) < 2 ) { |
|
| 218 | + throw new QueryException( 'Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
|
| 219 | + } |
|
| 217 | 220 | |
| 218 | - if ( count( $param ) == 2 ) |
|
| 219 | - $param[] = '='; |
|
| 221 | + if ( count( $param ) == 2 ) { |
|
| 222 | + $param[] = '='; |
|
| 223 | + } |
|
| 220 | 224 | |
| 221 | 225 | $param[ 0 ] = $this->queryStructure->prepare( $param[ 0 ] ); |
| 222 | 226 | $param[ 2 ] = trim( strtoupper( $param[ 2 ] ) ); |
@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $column = $this->queryStructure->prepare($column); |
| 30 | 30 | |
| 31 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
| 32 | - throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 31 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
| 32 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
| 35 | 36 | |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $column = $this->queryStructure->prepare($column); |
| 49 | 50 | |
| 50 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
| 51 | - throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 51 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
| 52 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column . ' DESC' ); |
| 54 | 56 | |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | */ |
| 74 | 76 | private function getOrderBySyntax() |
| 75 | 77 | { |
| 76 | - if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) |
|
| 77 | - return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
| 78 | + if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) { |
|
| 79 | + return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | return ''; |
| 80 | 83 | } |
@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $column = $this->queryStructure->prepare($column); |
| 30 | 30 | |
| 31 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
| 32 | - throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 31 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
| 32 | + throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column ); |
| 35 | 36 | |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $column = $this->queryStructure->prepare($column); |
| 49 | 50 | |
| 50 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
| 51 | - throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 51 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
| 52 | + throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column . ' DESC' ); |
| 54 | 56 | |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | */ |
| 74 | 76 | private function getGroupBySyntax() |
| 75 | 77 | { |
| 76 | - if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) |
|
| 77 | - return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' ); |
|
| 78 | + if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) { |
|
| 79 | + return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' ); |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | return ''; |
| 80 | 83 | } |
@@ -46,22 +46,26 @@ |
||
| 46 | 46 | { |
| 47 | 47 | $table = trim( $table ); |
| 48 | 48 | |
| 49 | - if ( '' === $table ) |
|
| 50 | - throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 49 | + if ( '' === $table ) { |
|
| 50 | + throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 51 | + } |
|
| 51 | 52 | |
| 52 | - if ( DbConfig::getInstance()->useTablePrefix() ) |
|
| 53 | - $table = str_ireplace( '::', DbConfig::getInstance()->getTablePrefix(), $table ); |
|
| 53 | + if ( DbConfig::getInstance()->useTablePrefix() ) { |
|
| 54 | + $table = str_ireplace( '::', DbConfig::getInstance()->getTablePrefix(), $table ); |
|
| 55 | + } |
|
| 54 | 56 | |
| 55 | 57 | return QueryHelper::addBacktick($table); |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | private function validateTableSubQuery( $table ) |
| 59 | 61 | { |
| 60 | - if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) |
|
| 61 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 62 | + if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) { |
|
| 63 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | - if ( !is_a( $table, QuerySelect::class ) ) |
|
| 64 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 66 | + if ( !is_a( $table, QuerySelect::class ) ) { |
|
| 67 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 68 | + } |
|
| 65 | 69 | |
| 66 | 70 | return $table; |
| 67 | 71 | } |
@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $limit = trim( $limit ); |
| 30 | 30 | |
| 31 | - if ( !QueryHelper::isInteger( $limit ) ) |
|
| 32 | - throw new QueryException( 'Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT ); |
|
| 31 | + if ( !QueryHelper::isInteger( $limit ) ) { |
|
| 32 | + throw new QueryException( 'Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT ); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | $limit = $this->queryStructure->bindParam('lim', (int)$limit); |
| 35 | 36 | |
@@ -41,8 +42,9 @@ discard block |
||
| 41 | 42 | |
| 42 | 43 | $offset = trim( $offset ); |
| 43 | 44 | |
| 44 | - if ( !QueryHelper::isInteger( $offset ) ) |
|
| 45 | - throw new QueryException( 'Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET ); |
|
| 45 | + if ( !QueryHelper::isInteger( $offset ) ) { |
|
| 46 | + throw new QueryException( 'Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET ); |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | $offset = $this->queryStructure->bindParam('ofs', (int)$offset); |
| 48 | 50 | |
@@ -53,8 +55,9 @@ discard block |
||
| 53 | 55 | |
| 54 | 56 | private function getLimitSyntax() |
| 55 | 57 | { |
| 56 | - if ( !$this->queryStructure->getElement( QueryStructure::LIMIT ) ) |
|
| 57 | - return ''; |
|
| 58 | + if ( !$this->queryStructure->getElement( QueryStructure::LIMIT ) ) { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 58 | 61 | |
| 59 | 62 | return 'LIMIT ' . $this->queryStructure->getElement( QueryStructure::LIMIT ); |
| 60 | 63 | } |