diff --git a/README.md b/README.md index e3883e2..f763c54 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,16 @@ $num = $this->connection->count('writers', null, '*'); $num = $this->connection->count('writers', null, 'name') ``` +## Running Queries from File + +In order to run all queries from a file, use `executeFromFile()` method: + +```php +$connection->executeFromFile('/path/to/file'); +``` + +**Note:** This method is not implemented to handle large data dumps. Use `mysqldump` instead, or another specialized backup utility instead. + ## Connection Factory Quickest way to connect is to use `ConnectionFactory` class: diff --git a/src/Connection/MysqliConnection.php b/src/Connection/MysqliConnection.php index 3470184..18b5558 100644 --- a/src/Connection/MysqliConnection.php +++ b/src/Connection/MysqliConnection.php @@ -437,6 +437,28 @@ public function inTransaction() return $this->transaction_level > 0; } + /** + * @param string $file_path + */ + public function executeFromFile($file_path) + { + if (!is_file($file_path)) { + throw new RuntimeException('File not found'); + } + + if ($this->link->multi_query(file_get_contents($file_path))) { + do { + if ($result = $this->link->store_result()) { + $result->free(); + } + + if (!$this->link->more_results()) { + break; + } + } while ($this->link->next_result()); + } + } + /** * {@inheritdoc} */ diff --git a/src/ConnectionInterface.php b/src/ConnectionInterface.php index f02dbeb..e4f567f 100644 --- a/src/ConnectionInterface.php +++ b/src/ConnectionInterface.php @@ -260,6 +260,11 @@ public function rollback(); */ public function inTransaction(); + /** + * @param string $file_path + */ + public function executeFromFile($file_path); + /** * @param string $database_name * @return bool diff --git a/test/resources/currencies.sql b/test/resources/currencies.sql new file mode 100644 index 0000000..0ba15de --- /dev/null +++ b/test/resources/currencies.sql @@ -0,0 +1,722 @@ +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('US Dollar','USD','$','$','2','0','1','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Canadian Dollar','CAD','CA$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Euro','EUR','€','€','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('United Arab Emirates Dirham','AED','AED','د.إ.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Afghan Afghani','AFN','Af','؋','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Albanian Lek','ALL','ALL','Lek','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Armenian Dram','AMD','AMD','դր.','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Argentine Peso','ARS','AR$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Aruba Florin','AWG','Afl.','Afl.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Australian Dollar','AUD','AU$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Azerbaijani Manat','AZN','man.','ман.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Bosnia-Herzegovina Convertible Mark','BAM','KM','KM','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Bangladeshi Taka','BDT','Tk','৳','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Bulgarian Lev','BGN','BGN','лв.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Bahraini Dinar','BHD','BD','د.ب.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Burundian Franc','BIF','FBu','FBu','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Brunei Dollar','BND','BN$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Bolivian Boliviano','BOB','Bs','Bs','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Brazilian Real','BRL','R$','R$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Botswanan Pula','BWP','BWP','P','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Belarusian Ruble','BYR','BYR','BYR','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Belize Dollar','BZD','BZ$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Congolese Franc','CDF','CDF','FrCD','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Swiss Franc','CHF','CHF','CHF','2','0.05','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Chilean Peso','CLP','CL$','$','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Chinese Yuan','CNY','CN¥','CN¥','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Colombian Peso','COP','CO$','$','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Costa Rican Colón','CRC','₡','₡','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Cape Verdean Escudo','CVE','CV$','CV$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Czech Republic Koruna','CZK','Kč','Kč','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Djiboutian Franc','DJF','Fdj','Fdj','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Danish Krone','DKK','Dkr','kr','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Dominican Peso','DOP','RD$','RD$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Algerian Dinar','DZD','DA','د.ج.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Estonian Kroon','EEK','Ekr','kr','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Egyptian Pound','EGP','EGP','ج.م.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Eritrean Nakfa','ERN','Nfk','Nfk','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Ethiopian Birr','ETB','Br','Br','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Fijian dollar','FJD','FJ$','FJ$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('British Pound Sterling','GBP','£','£','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Georgian Lari','GEL','GEL','GEL','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Ghanaian Cedi','GHS','GH₵','GH₵','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Guinean Franc','GNF','FG','FG','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Guatemalan Quetzal','GTQ','GTQ','Q','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Hong Kong Dollar','HKD','HK$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Honduran Lempira','HNL','HNL','L','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Croatian Kuna','HRK','kn','kn','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Hungarian Forint','HUF','Ft','Ft','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Indonesian Rupiah','IDR','Rp','Rp','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Israeli New Sheqel','ILS','₪','₪','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Indian Rupee','INR','Rs','টকা','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Iraqi Dinar','IQD','IQD','د.ع.‏','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Iranian Rial','IRR','IRR','﷼','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Icelandic Króna','ISK','Ikr','kr','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Jamaican Dollar','JMD','J$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Jordanian Dinar','JOD','JD','د.أ.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Japanese Yen','JPY','¥','¥','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Kenyan Shilling','KES','Ksh','Ksh','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Cambodian Riel','KHR','KHR','៛','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Comorian Franc','KMF','CF','FC','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('South Korean Won','KRW','₩','₩','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Kuwaiti Dinar','KWD','KD','د.ك.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Kazakhstani Tenge','KZT','KZT','тңг.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Lebanese Pound','LBP','LB£','ل.ل.‏','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Sri Lankan Rupee','LKR','SLRs','SL Re','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Lithuanian Litas','LTL','Lt','Lt','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Latvian Lats','LVL','Ls','Ls','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Libyan Dinar','LYD','LD','د.ل.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Moroccan Dirham','MAD','MAD','د.م.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Moldovan Leu','MDL','MDL','MDL','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Malagasy Ariary','MGA','MGA','MGA','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Macedonian Denar','MKD','MKD','MKD','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Myanma Kyat','MMK','MMK','K','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Mongolian Tugrik','MNT','MNT','₮','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Macanese Pataca','MOP','MOP$','MOP$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Mauritian Rupee','MUR','MURs','MURs','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Mexican Peso','MXN','MX$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Malaysian Ringgit','MYR','RM','RM','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Mozambican Metical','MZN','MTn','MTn','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Namibian Dollar','NAD','N$','N$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Nigerian Naira','NGN','₦','₦','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Nicaraguan Córdoba','NIO','C$','C$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Norwegian Krone','NOK','Nkr','kr','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Nepalese Rupee','NPR','NPRs','नेरू','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('New Zealand Dollar','NZD','NZ$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Omani Rial','OMR','OMR','ر.ع.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Panamanian Balboa','PAB','B/.','B/.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Peruvian Nuevo Sol','PEN','S/.','S/.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Philippine Peso','PHP','₱','₱','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Pakistani Rupee','PKR','PKRs','₨','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Polish Zloty','PLN','zł','zł','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Paraguayan Guarani','PYG','₲','₲','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Qatari Rial','QAR','QR','ر.ق.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Romanian Leu','RON','RON','RON','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Serbian Dinar','RSD','din.','дин.','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Russian Ruble','RUB','RUB','руб.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Rwandan Franc','RWF','RWF','FR','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Saudi Riyal','SAR','SR','ر.س.‏','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Sudanese Pound','SDG','SDG','SDG','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Swedish Krona','SEK','Skr','kr','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Singapore Dollar','SGD','S$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Somali Shilling','SOS','Ssh','Ssh','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Syrian Pound','SYP','SY£','ل.س.‏','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Thai Baht','THB','฿','฿','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Tunisian Dinar','TND','DT','د.ت.‏','3','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Tongan Paʻanga','TOP','T$','T$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Turkish Lira','TRY','TL','TL','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Trinidad and Tobago Dollar','TTD','TT$','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('New Taiwan Dollar','TWD','NT$','NT$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Tanzanian Shilling','TZS','TSh','TSh','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Ukrainian Hryvnia','UAH','₴','₴','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Ugandan Shilling','UGX','USh','USh','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Uruguayan Peso','UYU','$U','$','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Uzbekistan Som','UZS','UZS','UZS','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Venezuelan Bolívar','VEF','Bs.F.','Bs.F.','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Vietnamese Dong','VND','₫','₫','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('CFA Franc BEAC','XAF','FCFA','FCFA','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('CFA Franc BCEAO','XOF','CFA','CFA','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Yemeni Rial','YER','YR','ر.ي.‏','0','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('South African Rand','ZAR','R','R','2','0','0','2017-02-08 04:47:21'); + + + + +INSERT INTO `currencies` (`name`,`code`,`symbol`,`symbol_native`,`decimal_spaces`,`decimal_rounding`,`is_default`,`updated_at`) VALUES + ('Zambian Kwacha','ZMK','ZK','ZK','0','0','0','2017-02-08 04:47:21'); diff --git a/test/src/ExecuteFromFileTest.php b/test/src/ExecuteFromFileTest.php new file mode 100644 index 0000000..2c1e7ec --- /dev/null +++ b/test/src/ExecuteFromFileTest.php @@ -0,0 +1,82 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace ActiveCollab\DatabaseConnection\Test; + +use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; + +/** + * @package ActiveCollab\DatabaseConnection\Test + */ +class ExecuteFromFileTest extends TestCase +{ + /** + * @var MysqliConnection + */ + private $connection; + + /** + * {@inheritdoc} + */ + public function setUp() + { + parent::setUp(); + + $this->connection = new MysqliConnection($this->link); + + if ($this->connection->tableExists('currencies')) { + $this->connection->dropTable('currencies'); + } + + $this->connection->execute("CREATE TABLE IF NOT EXISTS `currencies` ( + `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, + `name` VARCHAR(191) DEFAULT NULL, + `code` VARCHAR(3) NOT NULL DEFAULT '', + `symbol` VARCHAR(5) DEFAULT NULL, + `symbol_native` VARCHAR(5) DEFAULT NULL, + `decimal_spaces` TINYINT UNSIGNED NOT NULL DEFAULT '2', + `decimal_rounding` DECIMAL(4, 3) NOT NULL DEFAULT '0', + `is_default` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', + `updated_at` DATETIME, + PRIMARY KEY (`id`), + UNIQUE `code` (`code`), + INDEX `updated_at` (`updated_at`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"); + } + + public function tearDown() + { + if ($this->connection->tableExists('currencies')) { + $this->connection->dropTable('currencies'); + } + + parent::tearDown(); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage File not found + */ + public function testExecuteFromNonExistingFile() + { + $unknown_file = dirname(__DIR__) . '/resources/unknown file'; + $this->assertFileNotExists($unknown_file); + + $this->connection->executeFromFile($unknown_file); + } + + public function testExecuteFromFile() + { + $this->assertSame(0, $this->connection->count('currencies')); + $this->connection->executeFromFile(dirname(__DIR__) . '/resources/currencies.sql'); + $this->assertSame(121, $this->connection->count('currencies')); + } +}