Mercurial > hg > orthanc-databases
annotate Framework/MySQL/MySQLResult.cpp @ 284:64bf8914f02e
sync + no more need of "-DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES" to dynamically link against system-wide orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 12 Jun 2021 08:49:52 +0200 |
parents | c82c2cf84ae8 |
children | 16aac0287485 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "MySQLResult.h" | |
23 | |
152 | 24 #include <Logging.h> |
25 #include <OrthancException.h> | |
0 | 26 |
6 | 27 #include <errmsg.h> |
0 | 28 #include <mysqld_error.h> |
29 | |
30 namespace OrthancDatabases | |
31 { | |
32 void MySQLResult::Step() | |
33 { | |
34 int code = mysql_stmt_fetch(statement_.GetObject()); | |
35 | |
36 if (code == 1) | |
37 { | |
38 unsigned int error = mysql_errno(database_.GetObject()); | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
39 |
0 | 40 if (error == 0) |
41 { | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
42 // This case occurs in requests without a result (e.g. if the |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
43 // SQL request is not a SELECT) |
0 | 44 done_ = true; |
45 } | |
46 else | |
47 { | |
240
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
48 database_.ThrowException(); |
0 | 49 } |
50 } | |
51 else | |
52 { | |
53 done_ = (code != 0 && | |
54 code != MYSQL_DATA_TRUNCATED); // Occurs if mysql_stmt_fetch_column() must be called | |
55 | |
56 FetchFields(); | |
57 } | |
58 } | |
59 | |
60 | |
61 IValue* MySQLResult::FetchField(size_t index) | |
62 { | |
63 return statement_.FetchResultField(index); | |
64 } | |
65 | |
66 | |
67 MySQLResult::MySQLResult(MySQLDatabase& db, | |
68 MySQLStatement& statement) : | |
69 database_(db), | |
70 statement_(statement) | |
71 { | |
72 // !!! https://dev.mysql.com/doc/refman/5.7/en/mysql-stmt-fetch.html | |
73 // https://gist.github.com/hoterran/6365915 | |
74 // https://github.com/hholzgra/connector-c-examples/blob/master/mysql_stmt_bind_result.c | |
75 | |
76 SetFieldsCount(statement_.GetResultFieldsCount()); | |
240
c82c2cf84ae8
added handling of CR_COMMANDS_OUT_OF_SYNC
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
77 |
0 | 78 Step(); |
79 } | |
80 | |
81 | |
82 MySQLResult::~MySQLResult() | |
83 { | |
84 // Reset the statement for further use | |
85 if (mysql_stmt_reset(statement_.GetObject()) != 0) | |
86 { | |
87 LOG(ERROR) << "Cannot reset the statement, expect an error"; | |
88 } | |
89 } | |
90 | |
91 | |
92 void MySQLResult::Next() | |
93 { | |
94 if (IsDone()) | |
95 { | |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
97 } | |
98 else | |
99 { | |
100 Step(); | |
101 } | |
102 } | |
103 } |