1 /*
2  * Copyright (C) 2018 Julien Viet
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 module hunt.database.driver.postgresql.impl.codec.ExtendedQueryCommandBaseCodec;
18 
19 import hunt.database.driver.postgresql.impl.codec.QueryCommandBaseCodec;
20 import hunt.database.driver.postgresql.impl.codec.PgRowDesc;
21 import hunt.database.driver.postgresql.impl.codec.PgPreparedStatement;
22 import hunt.database.driver.postgresql.impl.codec.RowResultDecoder;
23 
24 import hunt.database.base.impl.RowDesc;
25 import hunt.database.base.impl.command.ExtendedQueryCommandBase;
26 
27 import hunt.Exceptions;
28 import hunt.logging;
29 
30 abstract class ExtendedQueryCommandBaseCodec(R, C) : QueryCommandBaseCodec!(R, C) { // extends ExtendedQueryCommandBase!(R)
31 
32     this(C cmd) {
33         super(cmd);
34         decoder = new RowResultDecoder!(R)(cmd.isSingleton(), 
35             (cast(PgPreparedStatement)cmd.preparedStatement()).rowDesc());
36     }
37 
38     override
39     void handleRowDescription(PgRowDesc rowDescription) {
40         decoder = new RowResultDecoder!(R)(cmd.isSingleton(), rowDescription);
41     }
42 
43     override
44     void handleParseComplete() {
45         // Response to Parse
46         // version(HUNT_DB_DEBUG) info("running here");
47     }
48 
49     override
50     void handlePortalSuspended() {
51         R result = decoder.complete();
52         RowDesc desc = decoder.desc;
53         int size = decoder.size();
54         decoder.reset();
55         this.result = true;
56         cmd.resultHandler().handleResult(0, size, desc, result);
57     }
58 
59     override
60     void handleBindComplete() {
61         // Response to Bind
62         // version(HUNT_DB_DEBUG) info("running here");
63     }
64 }