Maurits van der Schee 6 years ago
parent
commit
d948946ba9

+ 8
- 3
api.php View File

@@ -184,7 +184,6 @@ class TempFileCache implements Cache
184 184
         $s = DIRECTORY_SEPARATOR;
185 185
         $ps = PATH_SEPARATOR;
186 186
         if ($config == '') {
187
-            $id = substr(md5(__FILE__), 0, 8);
188 187
             $this->path = sys_get_temp_dir() . $s . $prefix . self::SUFFIX;
189 188
         } elseif (strpos($config, $ps) === false) {
190 189
             $this->path = $config;
@@ -630,7 +629,7 @@ class ReflectedTable implements \JsonSerializable
630 629
         return $this->pk != null;
631 630
     }
632 631
 
633
-    public function getPk(): ReflectedColumn
632
+    public function getPk() /*: ?ReflectedColumn */
634 633
     {
635 634
         return $this->pk;
636 635
     }
@@ -1917,6 +1916,9 @@ class GenericDB
1917 1916
         if ($limit == 0) {
1918 1917
             return array();
1919 1918
         }
1919
+        if (!$columnOrdering) {
1920
+            return $this->selectAllUnordered($table, $columnNames, $condition);
1921
+        }
1920 1922
         $selectColumns = $this->columns->getSelect($table, $columnNames);
1921 1923
         $tableName = $table->getName();
1922 1924
         $condition = $this->addAuthorizationCondition($condition);
@@ -3825,7 +3827,10 @@ class OrderingInfo
3825 3827
             }
3826 3828
         }
3827 3829
         if (count($fields) == 0) {
3828
-            $fields[] = [$table->getPk()->getName(), 'ASC'];
3830
+            $pk = $table->getPk();
3831
+            if ($pk) {
3832
+                $fields[] = [$pk->getName(), 'ASC'];
3833
+            }
3829 3834
         }
3830 3835
         return $fields;
3831 3836
     }

+ 1
- 1
src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedTable.php View File

@@ -84,7 +84,7 @@ class ReflectedTable implements \JsonSerializable
84 84
         return $this->pk != null;
85 85
     }
86 86
 
87
-    public function getPk(): ReflectedColumn
87
+    public function getPk() /*: ?ReflectedColumn */
88 88
     {
89 89
         return $this->pk;
90 90
     }

+ 3
- 0
src/Tqdev/PhpCrudApi/Database/GenericDB.php View File

@@ -192,6 +192,9 @@ class GenericDB
192 192
         if ($limit == 0) {
193 193
             return array();
194 194
         }
195
+        if (!$columnOrdering) {
196
+            return $this->selectAllUnordered($table, $columnNames, $condition);
197
+        }
195 198
         $selectColumns = $this->columns->getSelect($table, $columnNames);
196 199
         $tableName = $table->getName();
197 200
         $condition = $this->addAuthorizationCondition($condition);

+ 4
- 1
src/Tqdev/PhpCrudApi/Record/OrderingInfo.php View File

@@ -26,7 +26,10 @@ class OrderingInfo
26 26
             }
27 27
         }
28 28
         if (count($fields) == 0) {
29
-            $fields[] = [$table->getPk()->getName(), 'ASC'];
29
+            $pk = $table->getPk();
30
+            if ($pk) {
31
+                $fields[] = [$pk->getName(), 'ASC'];
32
+            }
30 33
         }
31 34
         return $fields;
32 35
     }

+ 8
- 0
tests/fixtures/blog_mysql.sql View File

@@ -169,6 +169,14 @@ CREATE TABLE `invisibles` (
169 169
 INSERT INTO `invisibles` (`id`) VALUES
170 170
 ('e42c77c6-06a4-4502-816c-d112c7142e6d');
171 171
 
172
+DROP TABLE IF EXISTS `nopk`;
173
+CREATE TABLE `nopk` (
174
+  `id` varchar(36) NOT NULL
175
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
176
+
177
+INSERT INTO `nopk` (`id`) VALUES
178
+('e42c77c6-06a4-4502-816c-d112c7142e6d');
179
+
172 180
 SET foreign_key_checks = 1;
173 181
 
174 182
 -- 2016-11-05 13:11:47

+ 16
- 0
tests/fixtures/blog_pgsql.sql View File

@@ -32,6 +32,7 @@ DROP TABLE IF EXISTS barcodes CASCADE;
32 32
 DROP TABLE IF EXISTS barcodes2 CASCADE;
33 33
 DROP TABLE IF EXISTS "kunsthåndværk" CASCADE;
34 34
 DROP TABLE IF EXISTS invisibles CASCADE;
35
+DROP TABLE IF EXISTS nopk CASCADE;
35 36
 
36 37
 --
37 38
 -- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
@@ -169,6 +170,14 @@ CREATE TABLE "invisibles" (
169 170
   id character varying(36) NOT NULL
170 171
 );
171 172
 
173
+--
174
+-- Name: nopk; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
175
+--
176
+
177
+CREATE TABLE "nopk" (
178
+  id character varying(36) NOT NULL
179
+);
180
+
172 181
 --
173 182
 -- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres
174 183
 --
@@ -264,6 +273,13 @@ INSERT INTO "kunsthåndværk" ("id", "Umlauts ä_ö_ü-COUNT", "invisible") VALU
264 273
 INSERT INTO "invisibles" ("id") VALUES
265 274
 ('e42c77c6-06a4-4502-816c-d112c7142e6d');
266 275
 
276
+--
277
+-- Data for Name: nopk; Type: TABLE DATA; Schema: public; Owner: postgres
278
+--
279
+
280
+INSERT INTO "nopk" ("id") VALUES
281
+('e42c77c6-06a4-4502-816c-d112c7142e6d');
282
+
267 283
 --
268 284
 -- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
269 285
 --

+ 14
- 0
tests/fixtures/blog_sqlsrv.sql View File

@@ -118,6 +118,12 @@ DROP TABLE [invisibles]
118 118
 END
119 119
 GO
120 120
 
121
+IF (OBJECT_ID('nopk', 'U') IS NOT NULL)
122
+BEGIN
123
+DROP TABLE [nopk]
124
+END
125
+GO
126
+
121 127
 CREATE TABLE [categories](
122 128
 	[id] [int] IDENTITY,
123 129
 	[name] [nvarchar](255) NOT NULL,
@@ -231,6 +237,11 @@ CREATE TABLE [invisibles](
231 237
 )
232 238
 GO
233 239
 
240
+CREATE TABLE [nopk](
241
+	[id] [nvarchar](36)
242
+)
243
+GO
244
+
234 245
 INSERT [categories] ([name], [icon]) VALUES (N'announcement', NULL)
235 246
 GO
236 247
 INSERT [categories] ([name], [icon]) VALUES (N'article', NULL)
@@ -289,6 +300,9 @@ GO
289 300
 INSERT [invisibles] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
290 301
 GO
291 302
 
303
+INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
304
+GO
305
+
292 306
 ALTER TABLE [comments]  WITH CHECK ADD 	CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
293 307
 REFERENCES [posts] ([id])
294 308
 GO

+ 7
- 0
tests/functional/001_records/072_list_nopk.log View File

@@ -0,0 +1,7 @@
1
+GET /records/nopk
2
+===
3
+200
4
+Content-Type: application/json
5
+Content-Length: 59
6
+
7
+{"records":[{"id":"e42c77c6-06a4-4502-816c-d112c7142e6d"}]}

+ 2
- 2
tests/functional/002_columns/001_get_database.log View File

@@ -2,6 +2,6 @@ GET /columns
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json
5
-Content-Length: 2153
5
+Content-Length: 2224
6 6
 
7
-{"name":"php-crud-api","tables":[{"name":"barcodes","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]},{"name":"categories","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255}]},{"name":"countries","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp"},{"name":"visitors","type":"integer"}]},{"name":"kunsthåndværk","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"}]},{"name":"post_tags","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tags","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}
7
+{"name":"php-crud-api","tables":[{"name":"barcodes","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]},{"name":"categories","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255}]},{"name":"countries","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp"},{"name":"visitors","type":"integer"}]},{"name":"kunsthåndværk","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"}]},{"name":"nopk","columns":[{"name":"id","type":"varchar","length":36}]},{"name":"post_tags","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tags","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}

Loading…
Cancel
Save