1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "mysqlc_propertyids.hxx"
#include "mysqlc_general.hxx"
#include "mysqlc_prepared_resultset.hxx"
#include "mysqlc_resultsetmetadata.hxx"
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
#include <com/sun/star/sdbc/ResultSetType.hpp>
#include <com/sun/star/sdbc/FetchDirection.hpp>
#include <com/sun/star/sdbcx/CompareBookmark.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <sal/log.hxx>
using namespace rtl;
#include <cstdlib>
using namespace connectivity::mysqlc;
using namespace connectivity;
using namespace cppu;
using namespace com::sun::star;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
using namespace com::sun::star::sdbcx;
using namespace com::sun::star::container;
using namespace com::sun::star::io;
using namespace com::sun::star::util;
using namespace ::comphelper;
using ::osl::MutexGuard;
#include <typeindex>
namespace
{
std::type_index getTypeFromMysqlType(enum_field_types type)
{
switch (type)
{
case MYSQL_TYPE_TINY:
return std::type_index(typeid(sal_Int8));
case MYSQL_TYPE_SHORT:
return std::type_index(typeid(sal_Int16));
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_INT24:
return std::type_index(typeid(sal_Int32));
case MYSQL_TYPE_LONGLONG:
return std::type_index(typeid(sal_Int64));
case MYSQL_TYPE_FLOAT:
return std::type_index(typeid(float));
case MYSQL_TYPE_DOUBLE:
return std::type_index(typeid(double));
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
return std::type_index(typeid(DateTime));
case MYSQL_TYPE_DATE:
return std::type_index(typeid(Date));
case MYSQL_TYPE_TIME:
return std::type_index(typeid(Time));
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
return std::type_index(typeid(OUString));
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_SET:
case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_NULL:
default:
return std::type_index(typeid(nullptr));
}
}
}
bool OPreparedResultSet::fetchResult()
{
// allocate array if it does not exist
if (m_aData == nullptr)
{
m_aData.reset(new MYSQL_BIND[m_nColumnCount]);
memset(m_aData.get(), 0, m_nColumnCount * sizeof(MYSQL_BIND));
m_aMetaData.reset(new BindMetaData[m_nColumnCount]);
}
for (sal_Int32 i = 0; i < m_nColumnCount; ++i)
{
m_aMetaData[i].is_null = false;
m_aMetaData[i].length = 0l;
m_aMetaData[i].error = false;
m_aData[i].is_null = &m_aMetaData[i].is_null;
m_aData[i].buffer_length = m_aFields[i].type == MYSQL_TYPE_BLOB ? 0 : m_aFields[i].length;
m_aData[i].length = &m_aMetaData[i].length;
m_aData[i].error = &m_aMetaData[i].error;
m_aData[i].buffer = nullptr;
m_aData[i].buffer_type = m_aFields[i].type;
// allocates memory, if it is a fixed size type. If not then nullptr
mysqlc_sdbc_driver::allocateSqlVar(&m_aData[i].buffer, m_aData[i].buffer_type,
m_aFields[i].length);
}
mysql_stmt_bind_result(m_pStmt, m_aData.get());
int failure = mysql_stmt_fetch(m_pStmt);
for (sal_Int32 i = 0; i < m_nColumnCount; ++i)
{
if (*m_aData[i].error)
{
// expected if we have a BLOB, as buffer_length is set to 0. We want to
// fetch it piece by piece
// see https://bugs.mysql.com/file.php?id=12361&bug_id=33086
if (m_aData[i].buffer == nullptr)
{
m_aData[i].buffer_length = *m_aData[i].length;
m_aData[i].buffer = malloc(*m_aData[i].length);
mysql_stmt_fetch_column(m_pStmt, &m_aData[i], i, 0);
}
}
}
if (failure == 1)
{
MYSQL* pMysql = m_rConnection.getMysqlConnection();
mysqlc_sdbc_driver::throwSQLExceptionWithMsg(mysql_error(pMysql), mysql_sqlstate(pMysql),
mysql_errno(pMysql), *this, m_encoding);
}
else if (failure == MYSQL_NO_DATA)
return false;
return true;
}
OUString SAL_CALL OPreparedResultSet::getImplementationName()
{
return "com.sun.star.sdbcx.mysqlc.ResultSet";
}
uno::Sequence<OUString> SAL_CALL OPreparedResultSet::getSupportedServiceNames()
{
return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
}
sal_Bool SAL_CALL OPreparedResultSet::supportsService(const OUString& _rServiceName)
{
return cppu::supportsService(this, _rServiceName);
}
OPreparedResultSet::OPreparedResultSet(OConnection& rConn, OPreparedStatement* pStmt,
MYSQL_STMT* pMyStmt)
: OPreparedResultSet_BASE(m_aMutex)
, OPropertySetHelper(OPreparedResultSet_BASE::rBHelper)
, m_rConnection(rConn)
, m_aStatement(static_cast<OWeakObject*>(pStmt))
, m_pStmt(pMyStmt)
, m_encoding(rConn.getConnectionEncoding())
, m_nColumnCount(mysql_stmt_field_count(pMyStmt))
{
m_pResult = mysql_stmt_result_metadata(m_pStmt);
if (m_pResult != nullptr)
mysql_stmt_store_result(m_pStmt);
m_aFields = mysql_fetch_fields(m_pResult);
m_nRowCount = mysql_stmt_num_rows(pMyStmt);
}
void OPreparedResultSet::disposing()
{
OPropertySetHelper::disposing();
MutexGuard aGuard(m_aMutex);
m_aStatement = nullptr;
m_xMetaData = nullptr;
}
Any SAL_CALL OPreparedResultSet::queryInterface(const Type& rType)
{
Any aRet = OPropertySetHelper::queryInterface(rType);
if (!aRet.hasValue())
{
aRet = OPreparedResultSet_BASE::queryInterface(rType);
}
return aRet;
}
uno::Sequence<Type> SAL_CALL OPreparedResultSet::getTypes()
{
OTypeCollection aTypes(cppu::UnoType<XMultiPropertySet>::get(),
cppu::UnoType<XFastPropertySet>::get(),
cppu::UnoType<XPropertySet>::get());
return concatSequences(aTypes.getTypes(), OPreparedResultSet_BASE::getTypes());
}
sal_Int32 SAL_CALL OPreparedResultSet::findColumn(const OUString& columnName)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
MYSQL_FIELD* pFields = mysql_fetch_fields(m_pResult);
for (sal_Int32 i = 0; i < m_nColumnCount; ++i)
{
if (columnName.equalsIgnoreAsciiCaseAscii(pFields[i].name))
return i + 1; // sdbc indexes from 1
}
throw SQLException("The column name '" + columnName + "' is not valid.", *this, "42S22", 0,
Any());
}
template <typename T> T OPreparedResultSet::safelyRetrieveValue(sal_Int32 nColumnIndex)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(nColumnIndex);
if (*m_aData[nColumnIndex - 1].is_null)
{
m_bWasNull = true;
return T();
}
m_bWasNull = false;
return retrieveValue<T>(nColumnIndex);
}
template <typename T> T OPreparedResultSet::retrieveValue(sal_Int32 nColumnIndex)
{
if (getTypeFromMysqlType(m_aFields[nColumnIndex - 1].type) == std::type_index(typeid(T)))
return *static_cast<T*>(m_aData[nColumnIndex - 1].buffer);
else
return getRowSetValue(nColumnIndex);
}
template <> uno::Sequence<sal_Int8> OPreparedResultSet::retrieveValue(sal_Int32 column)
{
// TODO make conversion possible
return uno::Sequence<sal_Int8>(static_cast<sal_Int8 const*>(m_aData[column - 1].buffer),
*m_aData[column - 1].length);
}
template <> Date OPreparedResultSet::retrieveValue(sal_Int32 column)
{
if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(Date)))
return getRowSetValue(column);
const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer);
Date d;
d.Year = pTime->year;
d.Month = pTime->month;
d.Day = pTime->day;
return d;
}
template <> Time OPreparedResultSet::retrieveValue(sal_Int32 column)
{
if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(Time)))
return getRowSetValue(column);
const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer);
Time t;
t.Hours = pTime->hour;
t.Minutes = pTime->minute;
t.Seconds = pTime->second;
return t;
}
template <> DateTime OPreparedResultSet::retrieveValue(sal_Int32 column)
{
if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(DateTime)))
return getRowSetValue(column);
const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer);
DateTime t;
t.Year = pTime->year;
t.Month = pTime->month;
t.Day = pTime->day;
t.Hours = pTime->hour;
t.Minutes = pTime->minute;
t.Seconds = pTime->second;
return t;
}
template <> OUString OPreparedResultSet::retrieveValue(sal_Int32 column)
{
// redirect call to the appropriate method if needed
// BLOB can be simply read out as string
if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(OUString))
&& m_aFields[column - 1].type != MYSQL_TYPE_BLOB)
return getRowSetValue(column);
const char* sStr = static_cast<const char*>(m_aData[column - 1].buffer);
return OUString(sStr, *m_aData[column - 1].length, m_encoding);
}
ORowSetValue OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex)
{
switch (m_aFields[nColumnIndex - 1].type)
{
case MYSQL_TYPE_TINY:
return getByte(nColumnIndex);
case MYSQL_TYPE_SHORT:
return getShort(nColumnIndex);
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_INT24:
return getInt(nColumnIndex);
case MYSQL_TYPE_LONGLONG:
return getLong(nColumnIndex);
case MYSQL_TYPE_FLOAT:
return getFloat(nColumnIndex);
case MYSQL_TYPE_DOUBLE:
return getDouble(nColumnIndex);
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
return getTimestamp(nColumnIndex);
case MYSQL_TYPE_DATE:
return getDate(nColumnIndex);
case MYSQL_TYPE_TIME:
return getTime(nColumnIndex);
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
return getString(nColumnIndex);
case MYSQL_TYPE_BLOB:
throw SQLException("Column with type BLOB cannot be converted", *this, "22000", 1,
Any());
default:
SAL_WARN("connectivity.mysqlc", "OPreparedResultSet::getRowSetValue: unknown type: "
<< m_aFields[nColumnIndex - 1].type);
throw SQLException("Unknown column type when fetching result", *this, "22000", 1,
Any());
}
}
uno::Reference<XInputStream> SAL_CALL OPreparedResultSet::getBinaryStream(sal_Int32 /*column*/)
{
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBinaryStream",
*this);
return nullptr;
}
uno::Reference<XInputStream> SAL_CALL OPreparedResultSet::getCharacterStream(sal_Int32 /*column*/)
{
mysqlc_sdbc_driver::throwFeatureNotImplementedException(
"OPreparedResultSet::getCharacterStream", *this);
return nullptr;
}
sal_Bool SAL_CALL OPreparedResultSet::getBoolean(sal_Int32 column)
{
return safelyRetrieveValue<bool>(column);
}
sal_Int8 SAL_CALL OPreparedResultSet::getByte(sal_Int32 column)
{
return safelyRetrieveValue<sal_Int8>(column);
}
uno::Sequence<sal_Int8> SAL_CALL OPreparedResultSet::getBytes(sal_Int32 column)
{
return safelyRetrieveValue<uno::Sequence<sal_Int8>>(column);
}
Date SAL_CALL OPreparedResultSet::getDate(sal_Int32 column)
{
return safelyRetrieveValue<Date>(column);
}
double SAL_CALL OPreparedResultSet::getDouble(sal_Int32 column)
{
return safelyRetrieveValue<double>(column);
}
float SAL_CALL OPreparedResultSet::getFloat(sal_Int32 column)
{
return safelyRetrieveValue<float>(column);
}
sal_Int32 SAL_CALL OPreparedResultSet::getInt(sal_Int32 column)
{
return safelyRetrieveValue<sal_Int32>(column);
}
sal_Int32 SAL_CALL OPreparedResultSet::getRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return static_cast<sal_Int32>(mysql_field_tell(m_pResult));
}
sal_Int64 SAL_CALL OPreparedResultSet::getLong(sal_Int32 column)
{
return safelyRetrieveValue<sal_Int64>(column);
}
uno::Reference<XResultSetMetaData> SAL_CALL OPreparedResultSet::getMetaData()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
if (!m_xMetaData.is())
{
m_xMetaData = new OResultSetMetaData(m_rConnection, m_pResult);
}
return m_xMetaData;
}
uno::Reference<XArray> SAL_CALL OPreparedResultSet::getArray(sal_Int32 column)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getArray", *this);
return nullptr;
}
uno::Reference<XClob> SAL_CALL OPreparedResultSet::getClob(sal_Int32 column)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getClob", *this);
return nullptr;
}
uno::Reference<XBlob> SAL_CALL OPreparedResultSet::getBlob(sal_Int32 column)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBlob", *this);
return nullptr;
}
uno::Reference<XRef> SAL_CALL OPreparedResultSet::getRef(sal_Int32 column)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getRef", *this);
return nullptr;
}
Any SAL_CALL OPreparedResultSet::getObject(sal_Int32 column,
const uno::Reference<XNameAccess>& /* typeMap */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
Any aRet;
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getObject", *this);
return aRet;
}
sal_Int16 SAL_CALL OPreparedResultSet::getShort(sal_Int32 column)
{
return safelyRetrieveValue<sal_Int16>(column);
}
OUString SAL_CALL OPreparedResultSet::getString(sal_Int32 column)
{
return safelyRetrieveValue<OUString>(column);
}
Time SAL_CALL OPreparedResultSet::getTime(sal_Int32 column)
{
return safelyRetrieveValue<Time>(column);
}
DateTime SAL_CALL OPreparedResultSet::getTimestamp(sal_Int32 column)
{
return safelyRetrieveValue<DateTime>(column);
}
sal_Bool SAL_CALL OPreparedResultSet::isBeforeFirst()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_nCurrentRow == 0;
}
sal_Bool SAL_CALL OPreparedResultSet::isAfterLast()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_nCurrentRow > m_nRowCount;
}
sal_Bool SAL_CALL OPreparedResultSet::isFirst()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_nCurrentRow == 1 && !isAfterLast();
}
sal_Bool SAL_CALL OPreparedResultSet::isLast()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_nCurrentRow == m_nRowCount;
}
void SAL_CALL OPreparedResultSet::beforeFirst()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysql_stmt_data_seek(m_pStmt, 0);
m_nCurrentRow = 0;
m_aData.reset();
}
void SAL_CALL OPreparedResultSet::afterLast()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::afterLast", *this);
}
void SAL_CALL OPreparedResultSet::close()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
m_aData.reset();
m_aMetaData.reset();
if (m_pResult)
mysql_free_result(m_pResult);
mysql_stmt_free_result(m_pStmt);
dispose();
}
sal_Bool SAL_CALL OPreparedResultSet::first()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysql_stmt_data_seek(m_pStmt, 0);
m_nCurrentRow = 0;
next();
return true;
}
sal_Bool SAL_CALL OPreparedResultSet::last()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysql_stmt_data_seek(m_pStmt, m_nRowCount - 1);
next();
return true;
}
sal_Bool SAL_CALL OPreparedResultSet::absolute(sal_Int32 row)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
sal_Int32 nToGo = row < 0 ? m_nRowCount - row : row - 1;
if (nToGo >= m_nRowCount)
nToGo = m_nRowCount - 1;
if (nToGo < 0)
nToGo = 0;
mysql_stmt_data_seek(m_pStmt, nToGo);
next();
return true;
}
sal_Bool SAL_CALL OPreparedResultSet::relative(sal_Int32 row)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
if (row == 0)
return true;
sal_Int32 nToGo = m_nCurrentRow + row;
if (nToGo >= m_nRowCount)
nToGo = m_nRowCount - 1;
if (nToGo < 0)
nToGo = 0;
mysql_stmt_data_seek(m_pStmt, nToGo);
next();
m_nCurrentRow += row;
return true;
}
sal_Bool SAL_CALL OPreparedResultSet::previous()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
if (m_nCurrentRow <= 1)
return false;
mysql_stmt_data_seek(m_pStmt, m_nCurrentRow - 2);
next();
--m_nCurrentRow;
return true;
}
uno::Reference<uno::XInterface> SAL_CALL OPreparedResultSet::getStatement()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_aStatement.get();
}
sal_Bool SAL_CALL OPreparedResultSet::rowDeleted()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return false;
}
sal_Bool SAL_CALL OPreparedResultSet::rowInserted()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return false;
}
sal_Bool SAL_CALL OPreparedResultSet::rowUpdated()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return false;
}
sal_Bool SAL_CALL OPreparedResultSet::next()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
bool hasData = fetchResult();
// current field cannot be asked as a number. We have to keep track it
// manually.
m_nCurrentRow += 1;
return hasData;
}
sal_Bool SAL_CALL OPreparedResultSet::wasNull()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return m_bWasNull;
}
void SAL_CALL OPreparedResultSet::cancel()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
}
void SAL_CALL OPreparedResultSet::clearWarnings() {}
Any SAL_CALL OPreparedResultSet::getWarnings() { return Any(); }
void SAL_CALL OPreparedResultSet::insertRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
// you only have to implement this if you want to insert new rows
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::insertRow", *this);
}
void SAL_CALL OPreparedResultSet::updateRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
// only when you allow updates
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateRow", *this);
}
void SAL_CALL OPreparedResultSet::deleteRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::deleteRow", *this);
}
void SAL_CALL OPreparedResultSet::cancelRowUpdates()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::cancelRowUpdates",
*this);
}
void SAL_CALL OPreparedResultSet::moveToInsertRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
// only when you allow insert's
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::moveToInsertRow",
*this);
}
void SAL_CALL OPreparedResultSet::moveToCurrentRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
}
void SAL_CALL OPreparedResultSet::updateNull(sal_Int32 column)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateNull",
*this);
}
void SAL_CALL OPreparedResultSet::updateBoolean(sal_Int32 column, sal_Bool /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateBoolean",
*this);
}
void SAL_CALL OPreparedResultSet::updateByte(sal_Int32 column, sal_Int8 /* x */)
{
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
MutexGuard aGuard(m_aMutex);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateByte",
*this);
}
void SAL_CALL OPreparedResultSet::updateShort(sal_Int32 column, sal_Int16 /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateShort",
*this);
}
void SAL_CALL OPreparedResultSet::updateInt(sal_Int32 column, sal_Int32 /* x */)
{
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
MutexGuard aGuard(m_aMutex);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateInt", *this);
}
void SAL_CALL OPreparedResultSet::updateLong(sal_Int32 column, sal_Int64 /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateLong",
*this);
}
void SAL_CALL OPreparedResultSet::updateFloat(sal_Int32 column, float /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateFloat",
*this);
}
void SAL_CALL OPreparedResultSet::updateDouble(sal_Int32 column, double /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateDouble",
*this);
}
void SAL_CALL OPreparedResultSet::updateString(sal_Int32 column, const OUString& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateString",
*this);
}
void SAL_CALL OPreparedResultSet::updateBytes(sal_Int32 column,
const uno::Sequence<sal_Int8>& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateBytes",
*this);
}
void SAL_CALL OPreparedResultSet::updateDate(sal_Int32 column, const Date& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateDate",
*this);
}
void SAL_CALL OPreparedResultSet::updateTime(sal_Int32 column, const Time& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateTime",
*this);
}
void SAL_CALL OPreparedResultSet::updateTimestamp(sal_Int32 column, const DateTime& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateTimestamp",
*this);
}
void SAL_CALL OPreparedResultSet::updateBinaryStream(sal_Int32 column,
const uno::Reference<XInputStream>& /* x */,
sal_Int32 /* length */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException(
"OPreparedResultSet::updateBinaryStream", *this);
}
void SAL_CALL OPreparedResultSet::updateCharacterStream(sal_Int32 column,
const uno::Reference<XInputStream>& /* x */,
sal_Int32 /* length */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException(
"OPreparedResultSet::updateCharacterStream", *this);
}
void SAL_CALL OPreparedResultSet::refreshRow()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::refreshRow",
*this);
}
void SAL_CALL OPreparedResultSet::updateObject(sal_Int32 column, const Any& /* x */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateObject",
*this);
}
void SAL_CALL OPreparedResultSet::updateNumericObject(sal_Int32 column, const Any& /* x */,
sal_Int32 /* scale */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
checkColumnIndex(column);
mysqlc_sdbc_driver::throwFeatureNotImplementedException(
"OPreparedResultSet::updateNumericObject", *this);
}
// XRowLocate
Any SAL_CALL OPreparedResultSet::getBookmark()
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
// if you don't want to support bookmark you must remove the XRowLocate interface
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBookmark",
*this);
return Any();
}
sal_Bool SAL_CALL OPreparedResultSet::moveToBookmark(const Any& /* bookmark */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
return false;
}
sal_Bool SAL_CALL OPreparedResultSet::moveRelativeToBookmark(const Any& /* bookmark */,
sal_Int32 /* rows */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException(
"OPreparedResultSet::moveRelativeToBookmark", *this);
return false;
}
sal_Int32 SAL_CALL OPreparedResultSet::compareBookmarks(const Any& /* n1 */, const Any& /* n2 */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::compareBookmarks",
*this);
return CompareBookmark::NOT_EQUAL;
}
sal_Bool SAL_CALL OPreparedResultSet::hasOrderedBookmarks() { return false; }
sal_Int32 SAL_CALL OPreparedResultSet::hashBookmark(const Any& /* bookmark */)
{
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::hashBookmark",
*this);
return 0;
}
// XDeleteRows
uno::Sequence<sal_Int32>
SAL_CALL OPreparedResultSet::deleteRows(const uno::Sequence<Any>& /* rows */)
{
MutexGuard aGuard(m_aMutex);
checkDisposed(OPreparedResultSet_BASE::rBHelper.bDisposed);
mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::deleteRows",
*this);
return uno::Sequence<sal_Int32>();
}
IPropertyArrayHelper* OPreparedResultSet::createArrayHelper() const
{
uno::Sequence<Property> aProps(5);
Property* pProperties = aProps.getArray();
sal_Int32 nPos = 0;
pProperties[nPos++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION,
cppu::UnoType<sal_Int32>::get(), 0);
pProperties[nPos++]
= Property("FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0);
pProperties[nPos++] = Property("IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE,
cppu::UnoType<bool>::get(), PropertyAttribute::READONLY);
pProperties[nPos++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY,
cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY);
pProperties[nPos++] = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE,
cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY);
return new OPropertyArrayHelper(aProps);
}
IPropertyArrayHelper& OPreparedResultSet::getInfoHelper() { return *getArrayHelper(); }
sal_Bool OPreparedResultSet::convertFastPropertyValue(Any& /* rConvertedValue */,
Any& /* rOldValue */, sal_Int32 nHandle,
const Any& /* rValue */)
{
switch (nHandle)
{
case PROPERTY_ID_ISBOOKMARKABLE:
case PROPERTY_ID_CURSORNAME:
case PROPERTY_ID_RESULTSETCONCURRENCY:
case PROPERTY_ID_RESULTSETTYPE:
throw css::lang::IllegalArgumentException();
case PROPERTY_ID_FETCHDIRECTION:
case PROPERTY_ID_FETCHSIZE:
default:;
}
return false;
}
void OPreparedResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,
const Any& /* rValue */)
{
switch (nHandle)
{
case PROPERTY_ID_ISBOOKMARKABLE:
case PROPERTY_ID_CURSORNAME:
case PROPERTY_ID_RESULTSETCONCURRENCY:
case PROPERTY_ID_RESULTSETTYPE:
throw uno::Exception("cannot set prop " + OUString::number(nHandle), nullptr);
case PROPERTY_ID_FETCHDIRECTION:
break;
case PROPERTY_ID_FETCHSIZE:
break;
default:;
}
}
void OPreparedResultSet::getFastPropertyValue(Any& _rValue, sal_Int32 nHandle) const
{
switch (nHandle)
{
case PROPERTY_ID_ISBOOKMARKABLE:
_rValue <<= false;
break;
case PROPERTY_ID_CURSORNAME:
break;
case PROPERTY_ID_RESULTSETCONCURRENCY:
_rValue <<= ResultSetConcurrency::READ_ONLY;
break;
case PROPERTY_ID_RESULTSETTYPE:
_rValue <<= ResultSetType::SCROLL_INSENSITIVE;
break;
case PROPERTY_ID_FETCHDIRECTION:
_rValue <<= FetchDirection::FORWARD;
break;
case PROPERTY_ID_FETCHSIZE:
_rValue <<= sal_Int32(50);
break;
;
default:;
}
}
void SAL_CALL OPreparedResultSet::acquire() throw() { OPreparedResultSet_BASE::acquire(); }
void SAL_CALL OPreparedResultSet::release() throw() { OPreparedResultSet_BASE::release(); }
css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL OPreparedResultSet::getPropertySetInfo()
{
return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
}
void OPreparedResultSet::checkColumnIndex(sal_Int32 index)
{
if (!m_aData)
throw SQLException("Cursor out of range", *this, "HY109", 1, Any());
if (index < 1 || index > static_cast<int>(m_nColumnCount))
{
/* static object for efficiency or thread safety is a problem ? */
throw SQLException("index out of range", *this, "42S22", 1, Any());
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|