File tree Expand file tree Collapse file tree 4 files changed +104
-13
lines changed Expand file tree Collapse file tree 4 files changed +104
-13
lines changed Original file line number Diff line number Diff line change 1
1
* added retry function
2
+ * added optional type in prepare statment
2
3
3
4
## 1.5.6
4
5
Original file line number Diff line number Diff line change 21
21
use YdbPlatform \Ydb \Types \DateType ;
22
22
use YdbPlatform \Ydb \Types \JsonType ;
23
23
use YdbPlatform \Ydb \Types \ListType ;
24
+ use YdbPlatform \Ydb \Types \OptionalType ;
24
25
use YdbPlatform \Ydb \Types \UintType ;
25
26
use YdbPlatform \Ydb \Types \Utf8Type ;
26
27
use YdbPlatform \Ydb \Types \Int8Type ;
@@ -161,6 +162,11 @@ public function valueOfType($value, $type)
161
162
return (new TupleType ($ value ))->itemTypes (trim (substr ($ type , 6 , -1 )));
162
163
}
163
164
165
+ else if (substr ($ _type , 0 , 8 ) === 'OPTIONAL ' )
166
+ {
167
+ return (new OptionalType ($ value ))->itemType (trim (substr ($ type , 9 , -1 )));
168
+ }
169
+
164
170
throw new Exception ('YDB: Unknown [ ' . $ type . '] type. ' );
165
171
}
166
172
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace YdbPlatform \Ydb \Types ;
4
+
5
+ use Ydb \Type ;
6
+
7
+ class OptionalType extends AbstractType
8
+ {
9
+ /**
10
+ * @var string
11
+ */
12
+ protected $ itemType ;
13
+
14
+ /**
15
+ * @inherit
16
+ */
17
+ protected function normalizeValue ($ value )
18
+ {
19
+ return $ this ->typeValue ($ value , $ this ->itemType )->normalizeValue ($ value );
20
+ }
21
+
22
+ /**
23
+ * @param string $type
24
+ * @return $this
25
+ */
26
+ public function itemType ($ type )
27
+ {
28
+ $ this ->itemType = $ type ;
29
+ return $ this ;
30
+ }
31
+
32
+ /**
33
+ * @inherit
34
+ */
35
+ public function toYdbValue ()
36
+ {
37
+ return $ this ->typeValue ($ this ->value , $ this ->itemType )->toYdbValue ();
38
+ }
39
+
40
+ /**
41
+ * @inherit
42
+ */
43
+ public function getYdbType ()
44
+ {
45
+ $ type_id = $ this ->convertType ($ this ->itemType );
46
+
47
+ if ($ type_id )
48
+ {
49
+ return new Type ([
50
+ 'optional_type ' => new \Ydb \OptionalType ([
51
+ 'item ' => new Type ([
52
+ 'type_id ' => $ type_id ,
53
+ ]),
54
+ ]),
55
+ ]);
56
+ }
57
+ else
58
+ {
59
+ $ value = $ this ->typeValue ('' , $ this ->itemType );
60
+ return new Type ([
61
+ 'optional_type ' => new \Ydb \OptionalType ([
62
+ 'item ' => $ value ->getYdbType (),
63
+ ]),
64
+ ]);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @inherit
70
+ */
71
+ public function toYdbType ()
72
+ {
73
+ return $ this ->getYdbType ();
74
+ }
75
+
76
+ /**
77
+ * @inherit
78
+ */
79
+ protected function getYqlString ()
80
+ {
81
+ $ value = $ this ->typeValue ($ this ->value , $ this ->itemType )->toYqlString ();
82
+
83
+ return '( ' . $ value . ') ' ;
84
+ }
85
+
86
+ }
Original file line number Diff line number Diff line change @@ -45,12 +45,6 @@ public function test(){
45
45
];
46
46
47
47
$ checkTypes = [
48
- "Timestamp " => [
49
- "class " => TimestampType::class,
50
- "values " => [
51
- "2023-06-14 17:12:15.000001 "
52
- ]
53
- ],
54
48
"Bool " => [
55
49
"class " => BoolType::class,
56
50
"values " => [
@@ -161,6 +155,17 @@ public function test(){
161
155
$ table = $ ydb ->table ();
162
156
$ session = $ table ->createSession ();
163
157
158
+ $ query = "DECLARE \$v as Optional<Int32>; SELECT \$v as val; " ;
159
+ $ prepared = $ session ->prepare ($ query );
160
+ $ result = $ prepared ->execute ([
161
+ 'v ' => null ,
162
+ ]);
163
+
164
+ $ query = "DECLARE \$v as Optional<Int32>; SELECT \$v as val; " ;
165
+ $ prepared = $ session ->prepare ($ query );
166
+ $ result = $ prepared ->execute ([
167
+ 'v ' => 4 ,
168
+ ]);
164
169
165
170
$ query = "DECLARE \$v as Struct<x:Int32>; SELECT \$v as val; " ;
166
171
$ prepared = $ session ->prepare ($ query );
@@ -174,13 +179,6 @@ public function test(){
174
179
'v ' => [2 ],
175
180
]);
176
181
177
- // $query = "DECLARE \$v as Optional<Int32>; SELECT \$v as val;";
178
- // $prepared = $session->prepare($query);
179
- // $result = $prepared->execute([
180
- // 'v' => 2,
181
- // ]);
182
- // print_r($result);
183
-
184
182
foreach ($ checkTypes as $ type =>$ data ) {
185
183
$ query = "DECLARE \$v as $ type; SELECT \$v as val; " ;
186
184
$ prepared = $ session ->prepare ($ query );
You can’t perform that action at this time.
0 commit comments