| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function insert ( Row $row ) : int |
||
| 22 | { |
||
| 23 | if ( $this->tableName == null || $this->tableName == "" ) { |
||
| 24 | throw new SourceWatcherException( i18n::getInstance()->getText( EmbeddedDatabaseConnector::class, "No_Table_Name_Found" ) ); |
||
| 25 | } |
||
| 26 | |||
| 27 | $connection = $this->connect(); |
||
| 28 | |||
| 29 | // For some reason, for embedded databases such as SQLite, the DBAL Connection object will return false when asked if isConnected. |
||
| 30 | |||
| 31 | try { |
||
| 32 | $numberOfAffectedRows = $connection->insert( $this->tableName, $row->getAttributes() ); |
||
| 33 | |||
| 34 | $connection->close(); |
||
| 35 | } catch ( DBALException $dbalException ) { |
||
| 36 | $errorMessage = sprintf( "Something went wrong while trying to insert the row: %s", $dbalException->getMessage() ); |
||
| 37 | throw new SourceWatcherException( $errorMessage ); |
||
| 38 | } |
||
| 39 | |||
| 40 | return $numberOfAffectedRows; |
||
| 41 | } |
||
| 43 |