Browse Source

bugfix mssql fetch

Maurits van der Schee 5 years ago
parent
commit
5f74a9b86e

+ 30
- 15
api.php View File

3254
                 $joinPath = array();
3254
                 $joinPath = array();
3255
                 $tables = explode(',', $params['join'][$i]);
3255
                 $tables = explode(',', $params['join'][$i]);
3256
                 for ($depth = 0; $depth < min($maxDepth, count($tables)); $depth++) {
3256
                 for ($depth = 0; $depth < min($maxDepth, count($tables)); $depth++) {
3257
-                    array_push($joinPath, $table);
3257
+                    array_push($joinPath, $tables[$depth]);
3258
                     $tableCount += 1;
3258
                     $tableCount += 1;
3259
                     if ($tableCount == $maxTables) {
3259
                     if ($tableCount == $maxTables) {
3260
                         break;
3260
                         break;
3261
                     }
3261
                     }
3262
                 }
3262
                 }
3263
-                array_push($joinPaths, $joinPath);
3263
+                array_push($joinPaths, implode(',', $joinPath));
3264
                 if ($tableCount == $maxTables) {
3264
                 if ($tableCount == $maxTables) {
3265
                     break;
3265
                     break;
3266
                 }
3266
                 }
4583
             }
4583
             }
4584
         }
4584
         }
4585
         if (count($fields) == 0) {
4585
         if (count($fields) == 0) {
4586
-            $pk = $table->getPk();
4587
-            if ($pk) {
4588
-                $fields[] = [$pk->getName(), 'ASC'];
4589
-            } else {
4590
-                foreach ($table->getColumnNames() as $columnName) {
4591
-                    $fields[] = [$columnName, 'ASC'];
4592
-                }
4586
+            return $this->getDefaultColumnOrdering($table);
4587
+        }
4588
+        return $fields;
4589
+    }
4593
 
4590
 
4591
+    public function getDefaultColumnOrdering(ReflectedTable $table): array
4592
+    {
4593
+        $fields = array();
4594
+        $pk = $table->getPk();
4595
+        if ($pk) {
4596
+            $fields[] = [$pk->getName(), 'ASC'];
4597
+        } else {
4598
+            foreach ($table->getColumnNames() as $columnName) {
4599
+                $fields[] = [$columnName, 'ASC'];
4594
             }
4600
             }
4595
         }
4601
         }
4596
         return $fields;
4602
         return $fields;
4875
     public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
4881
     public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
4876
     {
4882
     {
4877
         $this->reflection = $reflection;
4883
         $this->reflection = $reflection;
4884
+        $this->ordering = new OrderingInfo();
4878
         $this->columns = $columns;
4885
         $this->columns = $columns;
4879
     }
4886
     }
4880
 
4887
 
4992
             } 
4999
             } 
4993
             if ($habtmValues != null) {
5000
             if ($habtmValues != null) {
4994
                 $this->fillFkValues($t2, $newRecords, $habtmValues->fkValues);
5001
                 $this->fillFkValues($t2, $newRecords, $habtmValues->fkValues);
4995
-                $this->setHabtmValues($t1, $t3, $records, $habtmValues);
5002
+                $this->setHabtmValues($t1, $t2, $records, $habtmValues);
4996
             }
5003
             }
4997
         }
5004
         }
4998
     }
5005
     }
5067
             $conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
5074
             $conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
5068
         }
5075
         }
5069
         $condition = OrCondition::fromArray($conditions);
5076
         $condition = OrCondition::fromArray($conditions);
5077
+        $columnOrdering = array();
5070
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
5078
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
5071
-        foreach ($db->selectAll($t2, $columnNames, $condition, array(), 0, $limit) as $record) {
5079
+        if ($limit != -1) {
5080
+            $columnOrdering = $this->ordering->getDefaultColumnOrdering($t2);
5081
+        }
5082
+        foreach ($db->selectAll($t2, $columnNames, $condition, $columnOrdering, 0, $limit) as $record) {
5072
             $records[] = $record;
5083
             $records[] = $record;
5073
         }
5084
         }
5074
     }
5085
     }
5113
 
5124
 
5114
         $pkIds = implode(',', array_keys($pkValues));
5125
         $pkIds = implode(',', array_keys($pkValues));
5115
         $condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
5126
         $condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
5127
+        $columnOrdering = array();
5116
 
5128
 
5117
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
5129
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
5118
-        $records = $db->selectAll($t3, $columnNames, $condition, array(), 0, $limit);
5130
+        if ($limit != -1) {
5131
+            $columnOrdering = $this->ordering->getDefaultColumnOrdering($t3);
5132
+        }
5133
+        $records = $db->selectAll($t3, $columnNames, $condition, $columnOrdering, 0, $limit);
5119
         foreach ($records as $record) {
5134
         foreach ($records as $record) {
5120
             $val1 = $record[$fk1Name];
5135
             $val1 = $record[$fk1Name];
5121
             $val2 = $record[$fk2Name];
5136
             $val2 = $record[$fk2Name];
5126
         return new HabtmValues($pkValues, $fkValues);
5141
         return new HabtmValues($pkValues, $fkValues);
5127
     }
5142
     }
5128
 
5143
 
5129
-    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues) /*: void*/
5144
+    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, HabtmValues $habtmValues) /*: void*/
5130
     {
5145
     {
5131
         $pkName = $t1->getPk()->getName();
5146
         $pkName = $t1->getPk()->getName();
5132
-        $t3Name = $t3->getName();
5147
+        $t2Name = $t2->getName();
5133
         foreach ($records as $i => $record) {
5148
         foreach ($records as $i => $record) {
5134
             $key = $record[$pkName];
5149
             $key = $record[$pkName];
5135
             $val = array();
5150
             $val = array();
5137
             foreach ($fks as $fk) {
5152
             foreach ($fks as $fk) {
5138
                 $val[] = $habtmValues->fkValues[$fk];
5153
                 $val[] = $habtmValues->fkValues[$fk];
5139
             }
5154
             }
5140
-            $records[$i][$t3Name] = $val;
5155
+            $records[$i][$t2Name] = $val;
5141
         }
5156
         }
5142
     }
5157
     }
5143
 }
5158
 }

+ 13
- 7
src/Tqdev/PhpCrudApi/Record/OrderingInfo.php View File

26
             }
26
             }
27
         }
27
         }
28
         if (count($fields) == 0) {
28
         if (count($fields) == 0) {
29
-            $pk = $table->getPk();
30
-            if ($pk) {
31
-                $fields[] = [$pk->getName(), 'ASC'];
32
-            } else {
33
-                foreach ($table->getColumnNames() as $columnName) {
34
-                    $fields[] = [$columnName, 'ASC'];
35
-                }
29
+            return $this->getDefaultColumnOrdering($table);
30
+        }
31
+        return $fields;
32
+    }
36
 
33
 
34
+    public function getDefaultColumnOrdering(ReflectedTable $table): array
35
+    {
36
+        $fields = array();
37
+        $pk = $table->getPk();
38
+        if ($pk) {
39
+            $fields[] = [$pk->getName(), 'ASC'];
40
+        } else {
41
+            foreach ($table->getColumnNames() as $columnName) {
42
+                $fields[] = [$columnName, 'ASC'];
37
             }
43
             }
38
         }
44
         }
39
         return $fields;
45
         return $fields;

+ 11
- 2
src/Tqdev/PhpCrudApi/Record/RelationJoiner.php View File

17
     public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
17
     public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
18
     {
18
     {
19
         $this->reflection = $reflection;
19
         $this->reflection = $reflection;
20
+        $this->ordering = new OrderingInfo();
20
         $this->columns = $columns;
21
         $this->columns = $columns;
21
     }
22
     }
22
 
23
 
209
             $conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
210
             $conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
210
         }
211
         }
211
         $condition = OrCondition::fromArray($conditions);
212
         $condition = OrCondition::fromArray($conditions);
213
+        $columnOrdering = array();
212
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
214
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
213
-        foreach ($db->selectAll($t2, $columnNames, $condition, array(), 0, $limit) as $record) {
215
+        if ($limit != -1) {
216
+            $columnOrdering = $this->ordering->getDefaultColumnOrdering($t2);
217
+        }
218
+        foreach ($db->selectAll($t2, $columnNames, $condition, $columnOrdering, 0, $limit) as $record) {
214
             $records[] = $record;
219
             $records[] = $record;
215
         }
220
         }
216
     }
221
     }
255
 
260
 
256
         $pkIds = implode(',', array_keys($pkValues));
261
         $pkIds = implode(',', array_keys($pkValues));
257
         $condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
262
         $condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
263
+        $columnOrdering = array();
258
 
264
 
259
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
265
         $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
260
-        $records = $db->selectAll($t3, $columnNames, $condition, array(), 0, $limit);
266
+        if ($limit != -1) {
267
+            $columnOrdering = $this->ordering->getDefaultColumnOrdering($t3);
268
+        }
269
+        $records = $db->selectAll($t3, $columnNames, $condition, $columnOrdering, 0, $limit);
261
         foreach ($records as $record) {
270
         foreach ($records as $record) {
262
             $val1 = $record[$fk1Name];
271
             $val1 = $record[$fk1Name];
263
             $val2 = $record[$fk2Name];
272
             $val2 = $record[$fk2Name];

Loading…
Cancel
Save