2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FIo_DataControlResultSetEnumerator.cpp
19 * @brief This is the implementation for the %_DataControlResultSetEnumerator class.
25 #include <unique_ptr.h>
28 #include <FBaseInteger.h>
29 #include <FBaseSysLog.h>
31 #include <FIo_FileImpl.h>
32 #include <FIo_DataControlResultSetEnumerator.h>
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
38 namespace Tizen { namespace Io
41 _DataControlResultSetEnumerator::_DataControlResultSetEnumerator(void)
45 , __columnTypeOffset(0)
46 , __columnNameOffset(0)
49 , __currentRowCount(0)
53 _DataControlResultSetEnumerator::~_DataControlResultSetEnumerator(void)
55 delete static_cast <File*>(__pFile);
56 __rowOffsetList.RemoveAll(true);
60 _DataControlResultSetEnumerator::SetPath(const String filePath)
63 SysAssertf(__pFile == null, "Already Set. Calling SetPath() twice or more on a same instance is not allowed for this class.");
64 unique_ptr<File> pFile(new (std::nothrow) File);
65 SysTryReturnResult(NID_IO, pFile != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
67 r = pFile->Construct(filePath, L"r");
68 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
70 __pFile = pFile.release();
76 _DataControlResultSetEnumerator::MoveNext(void)
78 int totalColumnNameSize = 0;
81 Integer* pCurrentOffset = null;
83 SysTryReturnResult(NID_IO, __pFile != null, E_OUT_OF_RANGE, "The result set does not exist.");
85 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
87 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
88 "This instance has not been properly constructed yet or has already been finalized.");
90 if (__currentOffset == 0)
92 r = pFile->Seek(FILESEEKPOSITION_BEGIN, 0);
93 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
95 ret = pFile->Read(&__rowCount, sizeof(int));
96 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
97 ret = pFile->Read(&__columnCount, sizeof(int));
98 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
99 ret = pFile->Read(&totalColumnNameSize, sizeof(int));
100 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
102 __columnTypeOffset = sizeof(int) * 3;
103 __columnNameOffset = __columnTypeOffset + __columnCount * sizeof(int);
104 __contentOffset = __columnNameOffset + totalColumnNameSize;
106 __currentOffset = __contentOffset;
108 r = __rowOffsetList.Add(* new (std::nothrow) Integer(__currentOffset));
109 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s]Propagated.", GetErrorMessage(r));
113 // check if dataoffset list contains next offset
114 pCurrentOffset = dynamic_cast < Integer* >(__rowOffsetList.GetAt(__currentRowCount + 1));
116 if (pCurrentOffset == null) // Move to next offset
121 // Reading till EOF is not required as we might have already cached the last content offset. So check and return
122 SysTryReturnResult(NID_IO, __currentRowCount < (__rowCount -1), E_OUT_OF_RANGE, "Reached to the end of the result set");
124 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
125 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
127 for (i = 0; i < __columnCount; i++)
129 r = pFile->Seek(FILESEEKPOSITION_CURRENT, sizeof(int)); // type
130 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
131 ret = pFile->Read(&size, sizeof(int));
135 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_OUT_OF_RANGE, "Reached to the end of the result set");
136 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
138 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
139 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
141 __currentOffset += sizeof(int) * 2 + size;
144 r = __rowOffsetList.Add(* new (std::nothrow) Integer(__currentOffset));
145 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s]Propagated.", GetErrorMessage(r));
149 __currentOffset = pCurrentOffset->ToInt();
159 _DataControlResultSetEnumerator::MovePrevious(void)
161 result r = E_SUCCESS;
162 Integer* pPreviousOffset = null;
164 SysTryReturnResult(NID_IO, __pFile != null, E_OUT_OF_RANGE, "The result set does not exist.");
166 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
168 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
169 "This instance has not been properly constructed yet or has already been finalized.");
171 SysTryReturnResult(NID_IO, __currentRowCount > 0, E_OUT_OF_RANGE,
172 "The Method has reached out of the result set.");
174 pPreviousOffset = dynamic_cast < Integer* >(__rowOffsetList.GetAt(__currentRowCount - 1));
175 if (!pPreviousOffset)
178 SysTryReturnResult(NID_IO, !IsFailed(r), r, "[%s]Propagated.", GetErrorMessage(r));
180 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error occurred.", GetErrorMessage(r));
184 __currentOffset = pPreviousOffset->ToInt();
190 _DataControlResultSetEnumerator::MoveFirst(void)
192 if (__currentOffset > 0)
194 __currentOffset = __contentOffset;
195 __currentRowCount = 0;
199 // MoveFirst is called for the first time before MoveNext() or MoveLast()
201 return this->MoveNext();
205 _DataControlResultSetEnumerator::MoveLast(void)
207 result r = E_SUCCESS;
208 Integer* pRowOffset = null;
211 SysTryReturnResult(NID_IO, __pFile != null, E_OUT_OF_RANGE, "The result set does not exist.");
213 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
215 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
216 "This instance has not been properly constructed yet or has already been finalized.");
218 if (__currentRowCount == (__rowCount - 1))
220 return E_SUCCESS; // Already @ last row
223 offsetCount = __rowOffsetList.GetCount();
225 if (__currentOffset == 0 && offsetCount == 0)
227 r = this->MoveNext(); // make a first move
228 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to MoveNext.");
231 // check if the rowOffsetList contains last row offset
233 if (offsetCount == __rowCount)
235 pRowOffset = dynamic_cast < Integer* >(__rowOffsetList.GetAt(__rowCount - 1)); // get last item
239 SysTryReturnResult(NID_IO, !IsFailed(r), r, "[%s]Propagated.", GetErrorMessage(r));
241 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error occurred.", GetErrorMessage(r));
244 __currentOffset = pRowOffset->ToInt();
245 __currentRowCount = __rowCount - 1;
249 // @ this time, List will not be empty.
250 pRowOffset = dynamic_cast < Integer* >(__rowOffsetList.GetAt(offsetCount - 1)); // get the last item in the list
253 __currentOffset = pRowOffset->ToInt();
254 __currentRowCount = offsetCount - 1;
257 // Move till last row offset.
258 for (int i = (__currentRowCount + 1); i < __rowCount; i++)
260 r = this->MoveNext(); // move till last row data offset
261 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to MoveNext.");
270 _DataControlResultSetEnumerator::Reset(void)
272 result r = E_SUCCESS;
274 //SysTryReturn(NID_IO, __pFile != null, E_INVALID_STATE, E_INVALID_STATE,
275 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
277 //SysTryReturn(NID_IO, __columnCount > 0, E_INVALID_STATE, E_INVALID_STATE,
278 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
281 __currentRowCount = 0;
282 __rowOffsetList.RemoveAll(true);
288 _DataControlResultSetEnumerator::GetIntAt(int columnIndex, int& value) const
290 long long int64Value = 0;
291 result r = E_SUCCESS;
293 r = GetInt64At(columnIndex, int64Value);
294 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
296 value = (int) int64Value;
302 _DataControlResultSetEnumerator::GetInt64At(int columnIndex, long long& value) const
306 long long readInt64 = 0;
308 result r = E_SUCCESS;
311 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
312 // "This instance has not been properly constructed yet or has already been finalized.");
314 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
315 "This instance has not been properly constructed yet or has already been finalized.");
317 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
318 "columnIndex is out of range");
320 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
322 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
323 "This instance has not been properly constructed yet or has already been finalized.");
325 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
326 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
328 for (i = 0; i < columnIndex; i++) // move to column index
330 ret = pFile->Read(&type, sizeof(int));
334 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
335 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
337 ret = pFile->Read(&size, sizeof(int));
338 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
340 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
341 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
344 ret = pFile->Read(&type, sizeof(int));
348 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
349 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
352 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_INT64, E_TYPE_MISMATCH,
353 "Trying to access column of different type.");
355 ret = pFile->Read(&size, sizeof(int));
356 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
358 ret = pFile->Read(&readInt64, size);
359 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
367 _DataControlResultSetEnumerator::GetDoubleAt(int columnIndex, double& value) const
371 double readDouble = 0;
373 result r = E_SUCCESS;
376 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
377 // "This instance has not been properly constructed yet or has already been finalized.");
379 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
380 "This instance has not been properly constructed yet or has already been finalized.");
382 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
383 "columnIndex is out of range");
385 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
387 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
388 "This instance has not been properly constructed yet or has already been finalized.");
390 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
391 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
393 for (i = 0; i < columnIndex; i++) // move to column index
395 ret = pFile->Read(&type, sizeof(int));
399 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
400 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
402 ret = pFile->Read(&size, sizeof(int));
403 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
405 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
406 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
409 ret = pFile->Read(&type, sizeof(int));
413 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "columnIndex is out of range");
414 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
417 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_DOUBLE, E_TYPE_MISMATCH,
418 "Trying to access column of different type.");
420 ret = pFile->Read(&size, sizeof(int));
421 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
423 ret = pFile->Read(&readDouble, size);
424 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
432 _DataControlResultSetEnumerator::GetStringAt(int columnIndex, String& value) const
437 result r = E_SUCCESS;
440 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
441 // "This instance has not been properly constructed yet or has already been finalized.");
443 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
444 "This instance has not been properly constructed yet or has already been finalized.");
446 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
447 "columnIndex is out of range");
449 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
451 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
452 "This instance has not been properly constructed yet or has already been finalized.");
454 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
455 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
457 for (i = 0; i < columnIndex; i++) // move to column index
459 ret = pFile->Read(&type, sizeof(int));
463 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
464 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
466 ret = pFile->Read(&size, sizeof(int));
467 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
469 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
470 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
473 ret = pFile->Read(&type, sizeof(int));
477 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
478 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
481 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_TEXT, E_TYPE_MISMATCH,
482 "Trying to access column of different type.");
484 ret = pFile->Read(&size, sizeof(int));
485 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
489 unique_ptr<char[]> pReadBuffer(new (std::nothrow) char[size + 1]);
490 SysTryReturnResult(NID_IO, pReadBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate memory for the read buffer.");
492 memset(pReadBuffer.get(), 0, size + 1);
494 ret = pFile->Read(pReadBuffer.get(), size);
495 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
496 value = String(pReadBuffer.get());
503 _DataControlResultSetEnumerator::GetBlobAt(int columnIndex, ByteBuffer& value) const
508 result r = E_SUCCESS;
511 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
512 // "This instance has not been properly constructed yet or has already been finalized.");
514 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
515 "This instance has not been properly constructed yet or has already been finalized.");
517 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
518 "columnIndex is out of range");
520 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
522 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
523 "This instance has not been properly constructed yet or has already been finalized.");
525 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
526 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
528 for (i = 0; i < columnIndex; i++) // move to column index
530 ret = pFile->Read(&type, sizeof(int));
534 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
535 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
537 ret = pFile->Read(&size, sizeof(int));
538 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
540 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
541 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
544 ret = pFile->Read(&type, sizeof(int));
548 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
549 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
551 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_BLOB, E_TYPE_MISMATCH,
552 "Trying to access column of different type.");
554 ret = pFile->Read(&size, sizeof(int));
555 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
559 unique_ptr<byte[]> pReadBuffer(new (std::nothrow) byte[size + 1]);
560 SysTryReturnResult(NID_IO, pReadBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate memory for the read buffer.");
562 memset(pReadBuffer.get(), 0, size + 1);
563 ret = pFile->Read(pReadBuffer.get(), size);
564 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
566 r = value.SetArray(pReadBuffer.get(), 0, size);
567 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
574 _DataControlResultSetEnumerator::GetBlobAt(int columnIndex, void* buffer, int bufSize) const
579 result r = E_SUCCESS;
582 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
583 // "This instance has not been properly constructed yet or has already been finalized.");
585 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
586 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
588 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
589 "columnIndex is out of range");
591 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
593 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
594 "This instance has not been properly constructed yet or has already been finalized.");
596 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
597 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
599 for (i = 0; i < columnIndex; i++) // move to column index
601 ret = pFile->Read(&type, sizeof(int));
605 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
606 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
608 ret = pFile->Read(&size, sizeof(int));
609 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
611 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
612 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
615 ret = pFile->Read(&type, sizeof(int));
619 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "The columnIndex is out of range.");
620 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
622 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_BLOB, E_TYPE_MISMATCH,
623 "Trying to access column of different type.");
625 ret = pFile->Read(&size, sizeof(int));
626 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
628 SysTryReturnResult(NID_IO, size <= bufSize, E_OVERFLOW, "The output buffer is insufficient.");
632 unique_ptr<byte[]> pReadBuffer(new (std::nothrow) byte[size + 1]);
633 SysTryReturnResult(NID_IO, pReadBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate memory for the read buffer.");
635 memset(pReadBuffer.get(), 0, size + 1);
636 ret = pFile->Read(pReadBuffer.get(), size);
637 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
639 memcpy(buffer, pReadBuffer.get(), size);
646 _DataControlResultSetEnumerator::GetDateTimeAt(int columnIndex, DateTime& value) const
650 char* pReadBuffer = null;
652 result r = E_SUCCESS;
655 //SysTryReturnResult(NID_IO, __pFile != null, E_INVALID_STATE,
656 // "This instance has not been properly constructed yet or has already been finalized.");
658 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_STATE,
659 "This instance has not been properly constructed yet or has already been finalized.");
661 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
662 "columnIndex is out of range");
664 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
666 SysTryReturnResult(NID_IO, pFile != null, E_INVALID_STATE,
667 "This instance has not been properly constructed yet or has already been finalized.");
669 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
670 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
672 for (i = 0; i < columnIndex; i++) // move to column index
674 ret = pFile->Read(&type, sizeof(int));
678 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "columnIndex is out of range");
679 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
681 ret = pFile->Read(&size, sizeof(int));
682 SysTryReturnResult(NID_IO, ret, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
684 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
685 SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "Failed to seek.");
688 ret = pFile->Read(&type, sizeof(int));
692 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "columnIndex is out of range");
693 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
695 SysTryReturnResult(NID_IO, type == DB_COLUMNTYPE_TEXT, E_TYPE_MISMATCH,
696 "Trying to access column of different type.");
698 ret = pFile->Read(&size, sizeof(int));
702 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "columnIndex is out of range");
703 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
708 pReadBuffer = (char*) malloc(size + 1);
709 SysTryReturn(NID_IO, pReadBuffer != NULL, E_SYSTEM, E_SYSTEM, "[E_OUT_OF_MEMORY] system error occurred.");
710 memset(pReadBuffer, 0, size + 1);
712 ret = pFile->Read(pReadBuffer, size);
717 SysTryReturnResult(NID_IO, !(r == E_END_OF_FILE), E_INVALID_ARG, "columnIndex is out of range");
718 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
721 r = DateTime::Parse(pReadBuffer, value);
729 _DataControlResultSetEnumerator::GetColumnCount(void) const
731 //SysTryReturn(NID_IO, __pFile != null, -1, E_INVALID_STATE,
732 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
734 SysTryReturn(NID_IO, __columnCount > 0, -1, E_INVALID_STATE,
735 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
737 SetLastResult(E_SUCCESS);
738 return __columnCount;
742 _DataControlResultSetEnumerator::GetColumnType(int columnIndex) const
744 DbColumnType columnType = DB_COLUMNTYPE_UNDEFINED;
748 result r = E_SUCCESS;
751 //SysTryReturn(NID_IO, __pFile != null, columnType, E_INVALID_STATE,
752 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
754 SysTryReturn(NID_IO, __columnCount > 0, columnType, E_INVALID_STATE,
755 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
757 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, columnType, E_INVALID_ARG,
758 "[E_INVALID_ARG] columnIndex is out of range");
760 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
762 SysTryReturn(NID_IO, pFile != null, columnType, E_INVALID_STATE,
763 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
765 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
766 SysTryReturn(NID_IO, !IsFailed(r), columnType, E_SYSTEM, "[E_SYSTEM] Failed to seek.");
768 for (i = 0; i < columnIndex; i++) // move to column index
770 ret = pFile->Read(&type, sizeof(int));
774 SysTryReturn(NID_IO, !(r == E_END_OF_FILE), columnType, E_INVALID_ARG, "[E_INVALID_ARG] The columnIndex is out of range.");
775 SysTryReturn(NID_IO, false, columnType, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
777 ret = pFile->Read(&size, sizeof(int));
778 SysTryReturn(NID_IO, ret, columnType, E_SYSTEM, "[E_SYSTEM] Failed to read data from the result set of the data control provider.");
780 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
781 SysTryReturn(NID_IO, !IsFailed(r), columnType, E_SYSTEM, "[E_SYSTEM] Failed to seek.");
784 ret = pFile->Read(&type, sizeof(int));
788 SysTryReturn(NID_IO, !(r == E_END_OF_FILE), DB_COLUMNTYPE_UNDEFINED, E_INVALID_ARG,
789 "[E_INVALID_ARG] columnIndex is out of range");
790 SysTryReturn(NID_IO, false, DB_COLUMNTYPE_UNDEFINED, E_SYSTEM,
791 "[%s] system error, errno: %d", GetErrorMessage(r), errno);
794 SetLastResult(E_SUCCESS);
799 columnType = DB_COLUMNTYPE_INT64;
803 columnType = DB_COLUMNTYPE_DOUBLE;
807 columnType = DB_COLUMNTYPE_TEXT;
811 columnType = DB_COLUMNTYPE_BLOB;
815 columnType = DB_COLUMNTYPE_NULL;
819 SysLogException(NID_IO, E_SYSTEM, "Found undefined column type (%d).", type);
827 _DataControlResultSetEnumerator::GetColumnName(int columnIndex) const
831 result r = E_SUCCESS;
833 //SysTryReturn(NID_IO, __pFile != null, columnName, E_INVALID_STATE,
834 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
836 SysTryReturn(NID_IO, __columnCount > 0, columnName, E_INVALID_STATE,
837 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
839 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, columnName, E_INVALID_ARG,
840 "[E_INVALID_ARG] columnIndex is out of range");
842 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
844 SysTryReturn(NID_IO, pFile != null, columnName, E_INVALID_STATE,
845 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
847 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __columnNameOffset);
848 SysTryReturn(NID_IO, !IsFailed(r), columnName, E_SYSTEM, "Failed to seek.");
849 for (i = 0; i < columnIndex + 1; i++)
851 r = pFile->Read(columnName);
854 SysTryReturn(NID_IO, !(r == E_END_OF_FILE), L"", E_INVALID_ARG, "[E_INVALID_ARG] columnIndex is out of range");
855 SysTryReturn(NID_IO, false, L"", E_SYSTEM, "[%s] system error", GetErrorMessage(r));
858 columnName.SetLength(columnName.GetLength() - 1);
860 SetLastResult(E_SUCCESS);
865 _DataControlResultSetEnumerator::GetColumnSize(int columnIndex) const
867 //SysTryReturn(NID_IO, __pFile != null, -1, E_INVALID_STATE,
868 // "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
870 SysTryReturn(NID_IO, __columnCount > 0, -1, E_INVALID_STATE,
871 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
873 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG, E_INVALID_ARG,
874 "[E_INVALID_ARG] columnIndex is out of range");
880 result r = E_SUCCESS;
882 _FileImpl* pFile = _FileImpl::GetInstance(*(static_cast< File* >(__pFile)));
884 SysTryReturn(NID_IO, pFile != null, -1, E_INVALID_STATE,
885 "[E_INVALID_STATE] This instance has not been properly constructed yet or has already been finalized.");
887 r = pFile->Seek(FILESEEKPOSITION_BEGIN, __currentOffset);
888 SysTryReturn(NID_IO, !IsFailed(r), -1, E_SYSTEM, "Failed to seek.");
890 for (i = 0; i < columnIndex; i++) // move to column index
892 ret = pFile->Read(&type, sizeof(int));
896 SysTryReturn(NID_IO, !(r == E_END_OF_FILE), -1, E_INVALID_ARG, "[E_INVALID_ARG] columnIndex is out of range");
897 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
899 ret = pFile->Read(&size, sizeof(int));
900 SysTryReturn(NID_IO, ret, -1, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
902 r = pFile->Seek(FILESEEKPOSITION_CURRENT, size);
903 SysTryReturn(NID_IO, !IsFailed(r), -1, E_SYSTEM, "Failed to seek.");
906 ret = pFile->Read(&type, sizeof(int));
910 SysTryReturn(NID_IO, !(r == E_END_OF_FILE), -1, E_INVALID_ARG, "[E_INVALID_ARG] columnIndex is out of range");
911 SysTryReturn(NID_IO, false, E_SYSTEM, E_SYSTEM, "[%s] system error", GetErrorMessage(r));
913 ret = pFile->Read(&size, sizeof(int));
914 SysTryReturn(NID_IO, ret, -1, E_SYSTEM, "Failed to read data from the result set of the data control provider.");
916 SetLastResult(E_SUCCESS);