|
1 | 1 | <?php |
2 | 2 | defined('BASEPATH') OR exit('No direct script access allowed'); |
3 | 3 |
|
4 | | -require APPPATH.'/traits/BaseQueryBuilder.php'; |
| 4 | +require_once APPPATH . '/traits/BaseQueryBuilder.php'; |
| 5 | +require_once APPPATH . '/traits/ExceptionThrow.php'; |
5 | 6 |
|
6 | 7 | class Model_app extends CI_Model { |
7 | 8 |
|
8 | | - use BaseQueryBuilder; |
| 9 | + use BaseQueryBuilder, ExceptionThrow; |
9 | 10 | /** |
10 | 11 | * Table's name inside databsae for each model |
11 | 12 | * @var [type] |
@@ -50,6 +51,8 @@ class Model_app extends CI_Model { |
50 | 51 | */ |
51 | 52 | function insert ( $arrayData, $table = false ) { |
52 | 53 |
|
| 54 | + if ( empty( $arrayData ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 55 | + |
53 | 56 | if ( !$table ) |
54 | 57 | $this->db->insert( $this->table, $arrayData ); |
55 | 58 | else{ |
@@ -91,6 +94,8 @@ function insert ( $arrayData, $table = false ) { |
91 | 94 | */ |
92 | 95 | function insert_batch ( $arrayData, $table = false ) { |
93 | 96 |
|
| 97 | + if ( empty( $arrayData ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 98 | + |
94 | 99 | if ( !$table ) |
95 | 100 | $insert = $this->db->insert_batch( $this->table, $arrayData ); |
96 | 101 | else |
@@ -126,6 +131,8 @@ function insert_batch ( $arrayData, $table = false ) { |
126 | 131 | */ |
127 | 132 | public function delete ( $where, $table = false ) { |
128 | 133 |
|
| 134 | + if ( empty( $where ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 135 | + |
129 | 136 | if ( !$table ) |
130 | 137 | $this->db->delete( $this->table ); |
131 | 138 | else{ |
@@ -210,6 +217,8 @@ function truncate ( $table = false ) { |
210 | 217 | */ |
211 | 218 | function get_last_data( $fieldToOrder, $where = false, $fieldToSelect = false, $table = false ) { |
212 | 219 |
|
| 220 | + if ( empty( $fieldToOrder ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 221 | + |
213 | 222 | if ( $fieldToSelect ) { |
214 | 223 | $column = $fieldToSelect; |
215 | 224 | } |
@@ -588,7 +597,10 @@ private function complexQueries ( $where = false, $fields = false, $table = fals |
588 | 597 | */ |
589 | 598 | function update ( $columnToUpdate, $usingCondition, $tableToUpdate = false ) |
590 | 599 | { |
591 | | - |
| 600 | + |
| 601 | + if ( empty( $columnToUpdate ) && empty( $usingCondition ) ) $this->InvalidArgExceptionThrow( 2 ); |
| 602 | + else if ( empty( $columnToUpdate ) || empty( $usingCondition ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 603 | + |
592 | 604 | $this->db->where( $usingCondition ); |
593 | 605 |
|
594 | 606 | if ( !$tableToUpdate ) |
@@ -636,6 +648,9 @@ function update ( $columnToUpdate, $usingCondition, $tableToUpdate = false ) |
636 | 648 | */ |
637 | 649 | function update_batch ( $columnToUpdate, $usingCondition, $tableToUpdate = false ) { |
638 | 650 |
|
| 651 | + if ( empty( $columnToUpdate ) && empty( $usingCondition ) ) $this->InvalidArgExceptionThrow( 2 ); |
| 652 | + else if ( empty( $columnToUpdate ) || empty( $usingCondition ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 653 | + |
639 | 654 | if ( !$tableToUpdate ) |
640 | 655 | $update = $this->db->update_batch( $this->table, $columnToUpdate, $usingCondition ); |
641 | 656 | else { |
@@ -670,6 +685,8 @@ function update_batch ( $columnToUpdate, $usingCondition, $tableToUpdate = fals |
670 | 685 | */ |
671 | 686 | function replace ( $data, $table = false ) { |
672 | 687 |
|
| 688 | + if ( empty( $data ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 689 | + |
673 | 690 | if ( !$table ) |
674 | 691 | $query = $this->db->replace( $this->table, $data); |
675 | 692 | else { |
@@ -740,6 +757,8 @@ private function joinTable ( $join ) { |
740 | 757 | */ |
741 | 758 | function max ( $fields, $where = false, $table = false, $join = false ) { |
742 | 759 |
|
| 760 | + if ( empty( $fields ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 761 | + |
743 | 762 | $this->db->select_max( $fields ); |
744 | 763 |
|
745 | 764 | if ( $where ) |
@@ -775,6 +794,8 @@ function max ( $fields, $where = false, $table = false, $join = false ) { |
775 | 794 | */ |
776 | 795 | function min ( $fields, $where = false, $table = false, $join = false ) { |
777 | 796 |
|
| 797 | + if ( empty( $fields ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 798 | + |
778 | 799 | $this->db->select_min( $fields ); |
779 | 800 |
|
780 | 801 | if ( $where ) |
@@ -810,6 +831,8 @@ function min ( $fields, $where = false, $table = false, $join = false ) { |
810 | 831 | */ |
811 | 832 | function avg ( $fields, $where = false, $table = false, $join = false ) { |
812 | 833 |
|
| 834 | + if ( empty( $fields ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 835 | + |
813 | 836 | $this->db->select_avg( $fields ); |
814 | 837 |
|
815 | 838 | if ( $where ) |
@@ -845,6 +868,8 @@ function avg ( $fields, $where = false, $table = false, $join = false ) { |
845 | 868 | */ |
846 | 869 | function sum ( $fields, $where = false, $table = false, $join = false ) { |
847 | 870 |
|
| 871 | + if ( empty( $fields ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 872 | + |
848 | 873 | $this->db->select_sum( $fields ); |
849 | 874 |
|
850 | 875 | if ( $where ) |
@@ -909,7 +934,9 @@ function count ( $where = false, $table = false, $join = false ) { |
909 | 934 | * The join implementation are same with @get_all_rows && @get_specified_row() method |
910 | 935 | */ |
911 | 936 | function where ( $arrValue, $table = false, $join = false ) { |
912 | | - |
| 937 | + |
| 938 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 939 | + |
913 | 940 | if ( $join ) $this->joinTable( $join ); |
914 | 941 |
|
915 | 942 | $this->db->where( $arrValue ); |
@@ -938,6 +965,8 @@ function where ( $arrValue, $table = false, $join = false ) { |
938 | 965 | */ |
939 | 966 | function or_where ( $arrValue, $table = false, $join = false ) { |
940 | 967 |
|
| 968 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 969 | + |
941 | 970 | if ( $join ) $this->joinTable( $join ); |
942 | 971 |
|
943 | 972 | $this->db->or_where( $arrValue ); |
@@ -965,7 +994,9 @@ function or_where ( $arrValue, $table = false, $join = false ) { |
965 | 994 | * The join implementation are same with @get_all_rows && @get_specified_row() method |
966 | 995 | */ |
967 | 996 | function having ( $arrValue, $table = false, $join = false ) { |
968 | | - |
| 997 | + |
| 998 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 999 | + |
969 | 1000 | if ( $join ) $this->joinTable( $join ); |
970 | 1001 |
|
971 | 1002 | $this->db->having( $arrValue ); |
@@ -994,6 +1025,8 @@ function having ( $arrValue, $table = false, $join = false ) { |
994 | 1025 | */ |
995 | 1026 | function or_having ( $arrValue, $table = false, $join = false ) { |
996 | 1027 |
|
| 1028 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1029 | + |
997 | 1030 | if ( $join ) $this->joinTable( $join ); |
998 | 1031 |
|
999 | 1032 | $this->db->or_having( $arrValue ); |
@@ -1022,6 +1055,8 @@ function or_having ( $arrValue, $table = false, $join = false ) { |
1022 | 1055 | */ |
1023 | 1056 | function where_in ( $arrValue, $table = false, $join = false ) { |
1024 | 1057 |
|
| 1058 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1059 | + |
1025 | 1060 | if ( $join ) $this->joinTable( $join ); |
1026 | 1061 |
|
1027 | 1062 | foreach( $arrValue as $key => $value ) { |
@@ -1052,6 +1087,8 @@ function where_in ( $arrValue, $table = false, $join = false ) { |
1052 | 1087 | */ |
1053 | 1088 | function or_where_in ( $arrValue, $table = false, $join = false ) { |
1054 | 1089 |
|
| 1090 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1091 | + |
1055 | 1092 | if ( $join ) $this->joinTable( $join ); |
1056 | 1093 |
|
1057 | 1094 | foreach( $arrValue as $key => $value ) { |
@@ -1082,6 +1119,8 @@ function or_where_in ( $arrValue, $table = false, $join = false ) { |
1082 | 1119 | */ |
1083 | 1120 | function where_not_in ( $arrValue, $table = false, $join = false ) { |
1084 | 1121 |
|
| 1122 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1123 | + |
1085 | 1124 | if ( $join ) $this->joinTable( $join ); |
1086 | 1125 |
|
1087 | 1126 | foreach( $arrValue as $key => $value ) { |
@@ -1112,6 +1151,8 @@ function where_not_in ( $arrValue, $table = false, $join = false ) { |
1112 | 1151 | */ |
1113 | 1152 | function or_where_not_in ( $arrValue, $table = false, $join = false ) { |
1114 | 1153 |
|
| 1154 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1155 | + |
1115 | 1156 | if ( $join ) $this->joinTable( $join ); |
1116 | 1157 |
|
1117 | 1158 | foreach( $arrValue as $key => $value ) { |
@@ -1143,6 +1184,8 @@ function or_where_not_in ( $arrValue, $table = false, $join = false ) { |
1143 | 1184 | */ |
1144 | 1185 | function like ( $arrValue, $table = false, $join = false ) { |
1145 | 1186 |
|
| 1187 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1188 | + |
1146 | 1189 | if ( $join ) $this->joinTable( $join ); |
1147 | 1190 |
|
1148 | 1191 | foreach( $arrValue as $key => $value ) { |
@@ -1174,6 +1217,8 @@ function like ( $arrValue, $table = false, $join = false ) { |
1174 | 1217 | */ |
1175 | 1218 | function like_before ( $arrValue, $table = false, $join = false ) { |
1176 | 1219 |
|
| 1220 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1221 | + |
1177 | 1222 | if ( $join ) $this->joinTable( $join ); |
1178 | 1223 |
|
1179 | 1224 | foreach( $arrValue as $key => $value ) { |
@@ -1205,6 +1250,8 @@ function like_before ( $arrValue, $table = false, $join = false ) { |
1205 | 1250 | */ |
1206 | 1251 | function like_after ( $arrValue, $table = false, $join = false ) { |
1207 | 1252 |
|
| 1253 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1254 | + |
1208 | 1255 | if ( $join ) $this->joinTable( $join ); |
1209 | 1256 |
|
1210 | 1257 | foreach( $arrValue as $key => $value ) { |
@@ -1236,6 +1283,8 @@ function like_after ( $arrValue, $table = false, $join = false ) { |
1236 | 1283 | */ |
1237 | 1284 | function or_like ( $arrValue, $table = false, $join = false ) { |
1238 | 1285 |
|
| 1286 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1287 | + |
1239 | 1288 | if ( $join ) $this->joinTable( $join ); |
1240 | 1289 |
|
1241 | 1290 | foreach( $arrValue as $key => $value ) { |
@@ -1267,6 +1316,8 @@ function or_like ( $arrValue, $table = false, $join = false ) { |
1267 | 1316 | */ |
1268 | 1317 | function or_like_before ( $arrValue, $table = false, $join = false ) { |
1269 | 1318 |
|
| 1319 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1320 | + |
1270 | 1321 | if ( $join ) $this->joinTable( $join ); |
1271 | 1322 |
|
1272 | 1323 | foreach( $arrValue as $key => $value ) { |
@@ -1298,6 +1349,8 @@ function or_like_before ( $arrValue, $table = false, $join = false ) { |
1298 | 1349 | */ |
1299 | 1350 | function or_like_after ( $arrValue, $table = false, $join = false ) { |
1300 | 1351 |
|
| 1352 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1353 | + |
1301 | 1354 | if ( $join ) $this->joinTable( $join ); |
1302 | 1355 |
|
1303 | 1356 | foreach( $arrValue as $key => $value ) { |
@@ -1329,6 +1382,8 @@ function or_like_after ( $arrValue, $table = false, $join = false ) { |
1329 | 1382 | */ |
1330 | 1383 | function not_like ( $arrValue, $table = false, $join = false ) { |
1331 | 1384 |
|
| 1385 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1386 | + |
1332 | 1387 | if ( $join ) $this->joinTable( $join ); |
1333 | 1388 |
|
1334 | 1389 | foreach( $arrValue as $key => $value ) { |
@@ -1360,6 +1415,8 @@ function not_like ( $arrValue, $table = false, $join = false ) { |
1360 | 1415 | */ |
1361 | 1416 | function not_like_before ( $arrValue, $table = false, $join = false ) { |
1362 | 1417 |
|
| 1418 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1419 | + |
1363 | 1420 | if ( $join ) $this->joinTable( $join ); |
1364 | 1421 |
|
1365 | 1422 | foreach( $arrValue as $key => $value ) { |
@@ -1391,6 +1448,8 @@ function not_like_before ( $arrValue, $table = false, $join = false ) { |
1391 | 1448 | */ |
1392 | 1449 | function not_like_after ( $arrValue, $table = false, $join = false ) { |
1393 | 1450 |
|
| 1451 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1452 | + |
1394 | 1453 | if ( $join ) $this->joinTable( $join ); |
1395 | 1454 |
|
1396 | 1455 | foreach( $arrValue as $key => $value ) { |
@@ -1422,6 +1481,8 @@ function not_like_after ( $arrValue, $table = false, $join = false ) { |
1422 | 1481 | */ |
1423 | 1482 | function or_not_like ( $arrValue, $table = false, $join = false ) { |
1424 | 1483 |
|
| 1484 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1485 | + |
1425 | 1486 | if ( $join ) $this->joinTable( $join ); |
1426 | 1487 |
|
1427 | 1488 | foreach( $arrValue as $key => $value ) { |
@@ -1453,6 +1514,8 @@ function or_not_like ( $arrValue, $table = false, $join = false ) { |
1453 | 1514 | */ |
1454 | 1515 | function or_not_like_before ( $arrValue, $table = false, $join = false ) { |
1455 | 1516 |
|
| 1517 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1518 | + |
1456 | 1519 | if ( $join ) $this->joinTable( $join ); |
1457 | 1520 |
|
1458 | 1521 | foreach( $arrValue as $key => $value ) { |
@@ -1484,6 +1547,8 @@ function or_not_like_before ( $arrValue, $table = false, $join = false ) { |
1484 | 1547 | */ |
1485 | 1548 | function or_not_like_after ( $arrValue, $table = false, $join = false ) { |
1486 | 1549 |
|
| 1550 | + if ( empty( $arrValue ) ) $this->InvalidArgExceptionThrow( 1 ); |
| 1551 | + |
1487 | 1552 | if ( $join ) $this->joinTable( $join ); |
1488 | 1553 |
|
1489 | 1554 | foreach( $arrValue as $key => $value ) { |
|
0 commit comments