2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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.
21 using System.Collections.Generic;
22 using System.Threading;
24 namespace Tizen.Applications.DataControl.Core
26 internal class CloneCursorCore : ICursor
28 internal const int MaxColumnNameSize = 1024;
29 private const string LogTag = "Tizen.Applications.DataControl";
30 private long _rowCount;
31 private int _columnCount;
32 private const int ResultNoData = -1;
33 private Interop.DataControl.SafeCursorHandle _cursor;
34 internal CloneCursorCore(Interop.DataControl.SafeCursorHandle cursor)
37 _columnCount = Interop.DataControl.GetColumnCount(cursor);
39 if (_columnCount == ResultNoData)
45 Interop.DataControl.First(cursor);
51 while (Interop.DataControl.Next(cursor) == (int)ResultType.Success);
52 Interop.DataControl.First(cursor);
55 public int GetColumnCount()
57 return Interop.DataControl.GetColumnCount(_cursor);
60 public ColumnType GetColumnType(int index)
65 if (index < 0 || index >= _columnCount)
67 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
70 ret = Interop.DataControl.GetItemType(_cursor, index, out type);
71 if (ret != ResultType.Success)
73 ErrorFactory.ThrowException(ret, false, "Column Index " + index.ToString());
76 return (ColumnType)type;
79 public string GetColumnName(int index)
83 StringBuilder columnName = new StringBuilder();
85 if (index < 0 || index >= _columnCount)
87 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
90 columnName.Length = MaxColumnNameSize;
91 ret = Interop.DataControl.GetColumnName(_cursor, index, columnName);
92 if (ret != ResultType.Success)
94 ErrorFactory.ThrowException(ret, false, "Column Index " + index.ToString());
97 retStr = columnName.ToString();
104 public long GetRowCount()
111 ResultType type = Interop.DataControl.Next(_cursor);
113 if (type != ResultType.Success)
123 ResultType type = Interop.DataControl.Prev(_cursor);
125 if (type != ResultType.Success)
135 ResultType type = Interop.DataControl.First(_cursor);
137 if (type != ResultType.Success)
145 public int GetIntValue(int index)
150 if (index < 0 || index >= _columnCount)
152 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
155 ret = Interop.DataControl.GetInt(_cursor, index, out value);
156 if (ret != ResultType.Success)
158 ErrorFactory.ThrowException(ret, false, "Column Index " + index.ToString());
164 public Int64 GetInt64Value(int index)
169 if (index < 0 || index >= _columnCount)
171 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
174 ret = Interop.DataControl.GetInt64(_cursor, index, out value);
175 if (ret != ResultType.Success)
177 ErrorFactory.ThrowException(ret, false, "Column Index " + index.ToString());
183 public double GetDoubleValue(int index)
188 if (index < 0 || index >= _columnCount)
190 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
193 ret = Interop.DataControl.Getdouble(_cursor, index, out value);
194 if (ret != ResultType.Success)
196 ErrorFactory.ThrowException(ret, false, "Column Index " + index.ToString());
202 public string GetStringValue(int index)
209 if (index < 0 || index >= _columnCount)
211 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
214 size = Interop.DataControl.GetItemSize(_cursor, index);
217 ErrorFactory.ThrowException(ResultType.IoError, false, "Invalid size");
220 value = new byte[size + 1];
221 ret = Interop.DataControl.GetText(_cursor, index, value);
222 if (ret != ResultType.Success)
224 ErrorFactory.ThrowException(ret, false);
227 text = Encoding.UTF8.GetString(value);
232 public byte[] GetBlobValue(int index)
238 if (index < 0 || index >= _columnCount)
240 ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
243 size = Interop.DataControl.GetItemSize(_cursor, index);
246 ErrorFactory.ThrowException(ResultType.IoError, false, "Invalid size");
249 byte_array = new byte[size];
250 ret = Interop.DataControl.GetBlob(_cursor, index, byte_array, size);
251 if (ret != ResultType.Success)
253 ErrorFactory.ThrowException(ret, false);