The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 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 | #undef LOG_TAG |
| 18 | #define LOG_TAG "CursorWindow" |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 19 | #define LOG_NDEBUG 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 21 | #include <inttypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <jni.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 23 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <android_runtime/AndroidRuntime.h> |
| 25 | |
| 26 | #include <utils/Log.h> |
| 27 | #include <utils/String8.h> |
| 28 | #include <utils/String16.h> |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 29 | #include <utils/Unicode.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <unistd.h> |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 34 | #include <sys/types.h> |
| 35 | #include <dirent.h> |
| 36 | |
| 37 | #undef LOG_NDEBUG |
| 38 | #define LOG_NDEBUG 1 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Mathias Agopian | 49d2b18 | 2012-02-27 18:11:20 -0800 | [diff] [blame] | 40 | #include <androidfw/CursorWindow.h> |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 41 | #include "android_os_Parcel.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | #include "android_util_Binder.h" |
Jeff Brown | e5360fb | 2011-10-31 17:48:13 -0700 | [diff] [blame] | 43 | #include "android_database_SQLiteCommon.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 45 | #include "core_jni_helpers.h" |
| 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | namespace android { |
| 48 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 49 | static struct { |
| 50 | jfieldID data; |
| 51 | jfieldID sizeCopied; |
| 52 | } gCharArrayBufferClassInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 54 | static jstring gEmptyString; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 56 | static void throwExceptionWithRowCol(JNIEnv* env, jint row, jint column) { |
| 57 | String8 msg; |
| 58 | msg.appendFormat("Couldn't read row %d, col %d from CursorWindow. " |
| 59 | "Make sure the Cursor is initialized correctly before accessing data from it.", |
| 60 | row, column); |
| 61 | jniThrowException(env, "java/lang/IllegalStateException", msg.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 64 | static void throwUnknownTypeException(JNIEnv * env, jint type) { |
| 65 | String8 msg; |
| 66 | msg.appendFormat("UNKNOWN type %d", type); |
| 67 | jniThrowException(env, "java/lang/IllegalStateException", msg.string()); |
| 68 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 70 | static int getFdCount() { |
| 71 | char fdpath[PATH_MAX]; |
| 72 | int count = 0; |
| 73 | snprintf(fdpath, PATH_MAX, "/proc/%d/fd", getpid()); |
| 74 | DIR *dir = opendir(fdpath); |
| 75 | if (dir != NULL) { |
| 76 | struct dirent *dirent; |
| 77 | while ((dirent = readdir(dir))) { |
| 78 | count++; |
| 79 | } |
| 80 | count -= 2; // discount "." and ".." |
| 81 | closedir(dir); |
| 82 | } |
| 83 | return count; |
| 84 | } |
| 85 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 86 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jstring nameObj, jint cursorWindowSize) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 87 | String8 name; |
Jeff Brown | 5a05c23 | 2012-01-12 12:04:22 -0800 | [diff] [blame] | 88 | const char* nameStr = env->GetStringUTFChars(nameObj, NULL); |
| 89 | name.setTo(nameStr); |
| 90 | env->ReleaseStringUTFChars(nameObj, nameStr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 91 | |
| 92 | CursorWindow* window; |
Jeff Brown | 5e5d6d8 | 2011-10-12 15:41:34 -0700 | [diff] [blame] | 93 | status_t status = CursorWindow::create(name, cursorWindowSize, &window); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 94 | if (status || !window) { |
Makoto Onuki | 2276cea | 2019-04-02 14:05:05 -0700 | [diff] [blame] | 95 | jniThrowExceptionFmt(env, |
| 96 | "android/database/CursorWindowAllocationException", |
| 97 | "Could not allocate CursorWindow '%s' of size %d due to error %d.", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 98 | name.string(), cursorWindowSize, status); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 99 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 102 | LOG_WINDOW("nativeInitializeEmpty: window = %p", window); |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 103 | return reinterpret_cast<jlong>(window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 106 | static jlong nativeCreateFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 107 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 109 | CursorWindow* window; |
| 110 | status_t status = CursorWindow::createFromParcel(parcel, &window); |
| 111 | if (status || !window) { |
Makoto Onuki | 2276cea | 2019-04-02 14:05:05 -0700 | [diff] [blame] | 112 | jniThrowExceptionFmt(env, |
| 113 | "android/database/CursorWindowAllocationException", |
| 114 | "Could not create CursorWindow from Parcel due to error %d, process fd count=%d", |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 115 | status, getFdCount()); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 116 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 119 | LOG_WINDOW("nativeInitializeFromBinder: numRows = %d, numColumns = %d, window = %p", |
| 120 | window->getNumRows(), window->getNumColumns(), window); |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 121 | return reinterpret_cast<jlong>(window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 124 | static void nativeDispose(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 125 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 126 | if (window) { |
| 127 | LOG_WINDOW("Closing window %p", window); |
| 128 | delete window; |
| 129 | } |
| 130 | } |
| 131 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 132 | static jstring nativeGetName(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 650de3d | 2011-10-27 14:52:28 -0700 | [diff] [blame] | 133 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 134 | return env->NewStringUTF(window->name().string()); |
| 135 | } |
| 136 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 137 | static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jlong windowPtr, |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 138 | jobject parcelObj) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 139 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 140 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 141 | |
| 142 | status_t status = window->writeToParcel(parcel); |
| 143 | if (status) { |
| 144 | String8 msg; |
| 145 | msg.appendFormat("Could not write CursorWindow to Parcel due to error %d.", status); |
| 146 | jniThrowRuntimeException(env, msg.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 150 | static void nativeClear(JNIEnv * env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 151 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 152 | LOG_WINDOW("Clearing window %p", window); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 153 | status_t status = window->clear(); |
| 154 | if (status) { |
| 155 | LOG_WINDOW("Could not clear window. error=%d", status); |
| 156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 159 | static jint nativeGetNumRows(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 160 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 161 | return window->getNumRows(); |
| 162 | } |
| 163 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 164 | static jboolean nativeSetNumColumns(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 165 | jint columnNum) { |
| 166 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 167 | status_t status = window->setNumColumns(columnNum); |
| 168 | return status == OK; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 171 | static jboolean nativeAllocRow(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 172 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 173 | status_t status = window->allocRow(); |
| 174 | return status == OK; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 177 | static void nativeFreeLastRow(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 178 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 179 | window->freeLastRow(); |
| 180 | } |
| 181 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 182 | static jint nativeGetType(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 183 | jint row, jint column) { |
| 184 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 185 | LOG_WINDOW("returning column type affinity for %d,%d from %p", row, column, window); |
| 186 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 187 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 188 | if (!fieldSlot) { |
Jeff Brown | aa32c30 | 2011-10-07 13:15:59 -0700 | [diff] [blame] | 189 | // FIXME: This is really broken but we have CTS tests that depend |
| 190 | // on this legacy behavior. |
| 191 | //throwExceptionWithRowCol(env, row, column); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 192 | return CursorWindow::FIELD_TYPE_NULL; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 193 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 194 | return window->getFieldSlotType(fieldSlot); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 197 | static jbyteArray nativeGetBlob(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 198 | jint row, jint column) { |
| 199 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 200 | LOG_WINDOW("Getting blob for %d,%d from %p", row, column, window); |
| 201 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 202 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 203 | if (!fieldSlot) { |
| 204 | throwExceptionWithRowCol(env, row, column); |
| 205 | return NULL; |
| 206 | } |
| 207 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 208 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 209 | if (type == CursorWindow::FIELD_TYPE_BLOB || type == CursorWindow::FIELD_TYPE_STRING) { |
| 210 | size_t size; |
| 211 | const void* value = window->getFieldSlotValueBlob(fieldSlot, &size); |
Fyodor Kupolov | eb6de6f | 2017-02-22 14:12:50 -0800 | [diff] [blame] | 212 | if (!value) { |
| 213 | throw_sqlite3_exception(env, "Native could not read blob slot"); |
| 214 | return NULL; |
| 215 | } |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 216 | jbyteArray byteArray = env->NewByteArray(size); |
| 217 | if (!byteArray) { |
| 218 | env->ExceptionClear(); |
| 219 | throw_sqlite3_exception(env, "Native could not create new byte[]"); |
| 220 | return NULL; |
| 221 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 222 | env->SetByteArrayRegion(byteArray, 0, size, static_cast<const jbyte*>(value)); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 223 | return byteArray; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 224 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 225 | throw_sqlite3_exception(env, "INTEGER data in nativeGetBlob "); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 226 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 227 | throw_sqlite3_exception(env, "FLOAT data in nativeGetBlob "); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 228 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 229 | // do nothing |
| 230 | } else { |
| 231 | throwUnknownTypeException(env, type); |
| 232 | } |
| 233 | return NULL; |
| 234 | } |
| 235 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 236 | static jstring nativeGetString(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 237 | jint row, jint column) { |
| 238 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 239 | LOG_WINDOW("Getting string for %d,%d from %p", row, column, window); |
| 240 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 241 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 242 | if (!fieldSlot) { |
| 243 | throwExceptionWithRowCol(env, row, column); |
| 244 | return NULL; |
| 245 | } |
| 246 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 247 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 248 | if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 249 | size_t sizeIncludingNull; |
| 250 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
Fyodor Kupolov | eb6de6f | 2017-02-22 14:12:50 -0800 | [diff] [blame] | 251 | if (!value) { |
| 252 | throw_sqlite3_exception(env, "Native could not read string slot"); |
| 253 | return NULL; |
| 254 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 255 | if (sizeIncludingNull <= 1) { |
Jeff Brown | 715311f | 2011-10-07 14:17:09 -0700 | [diff] [blame] | 256 | return gEmptyString; |
| 257 | } |
| 258 | // Convert to UTF-16 here instead of calling NewStringUTF. NewStringUTF |
| 259 | // doesn't like UTF-8 strings with high codepoints. It actually expects |
| 260 | // Modified UTF-8 with encoded surrogate pairs. |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 261 | String16 utf16(value, sizeIncludingNull - 1); |
Jeff Brown | 715311f | 2011-10-07 14:17:09 -0700 | [diff] [blame] | 262 | return env->NewString(reinterpret_cast<const jchar*>(utf16.string()), utf16.size()); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 263 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 264 | int64_t value = window->getFieldSlotValueLong(fieldSlot); |
| 265 | char buf[32]; |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 266 | snprintf(buf, sizeof(buf), "%" PRId64, value); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 267 | return env->NewStringUTF(buf); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 268 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 269 | double value = window->getFieldSlotValueDouble(fieldSlot); |
| 270 | char buf[32]; |
| 271 | snprintf(buf, sizeof(buf), "%g", value); |
| 272 | return env->NewStringUTF(buf); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 273 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 274 | return NULL; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 275 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 276 | throw_sqlite3_exception(env, "Unable to convert BLOB to string"); |
| 277 | return NULL; |
| 278 | } else { |
| 279 | throwUnknownTypeException(env, type); |
| 280 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 284 | static jcharArray allocCharArrayBuffer(JNIEnv* env, jobject bufferObj, size_t size) { |
| 285 | jcharArray dataObj = jcharArray(env->GetObjectField(bufferObj, |
| 286 | gCharArrayBufferClassInfo.data)); |
| 287 | if (dataObj && size) { |
| 288 | jsize capacity = env->GetArrayLength(dataObj); |
| 289 | if (size_t(capacity) < size) { |
| 290 | env->DeleteLocalRef(dataObj); |
| 291 | dataObj = NULL; |
| 292 | } |
| 293 | } |
| 294 | if (!dataObj) { |
| 295 | jsize capacity = size; |
| 296 | if (capacity < 64) { |
| 297 | capacity = 64; |
| 298 | } |
| 299 | dataObj = env->NewCharArray(capacity); // might throw OOM |
| 300 | if (dataObj) { |
| 301 | env->SetObjectField(bufferObj, gCharArrayBufferClassInfo.data, dataObj); |
| 302 | } |
| 303 | } |
| 304 | return dataObj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 307 | static void fillCharArrayBufferUTF(JNIEnv* env, jobject bufferObj, |
| 308 | const char* str, size_t len) { |
| 309 | ssize_t size = utf8_to_utf16_length(reinterpret_cast<const uint8_t*>(str), len); |
| 310 | if (size < 0) { |
| 311 | size = 0; // invalid UTF8 string |
| 312 | } |
| 313 | jcharArray dataObj = allocCharArrayBuffer(env, bufferObj, size); |
| 314 | if (dataObj) { |
| 315 | if (size) { |
| 316 | jchar* data = static_cast<jchar*>(env->GetPrimitiveArrayCritical(dataObj, NULL)); |
Jeff Brown | d0ff68d | 2011-10-07 13:28:18 -0700 | [diff] [blame] | 317 | utf8_to_utf16_no_null_terminator(reinterpret_cast<const uint8_t*>(str), len, |
Sergio Giro | 8f7b8a1 | 2016-07-21 14:44:07 +0100 | [diff] [blame] | 318 | reinterpret_cast<char16_t*>(data), (size_t) size); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 319 | env->ReleasePrimitiveArrayCritical(dataObj, data, 0); |
| 320 | } |
| 321 | env->SetIntField(bufferObj, gCharArrayBufferClassInfo.sizeCopied, size); |
| 322 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 325 | static void clearCharArrayBuffer(JNIEnv* env, jobject bufferObj) { |
| 326 | jcharArray dataObj = allocCharArrayBuffer(env, bufferObj, 0); |
| 327 | if (dataObj) { |
| 328 | env->SetIntField(bufferObj, gCharArrayBufferClassInfo.sizeCopied, 0); |
| 329 | } |
| 330 | } |
| 331 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 332 | static void nativeCopyStringToBuffer(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 333 | jint row, jint column, jobject bufferObj) { |
| 334 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 335 | LOG_WINDOW("Copying string for %d,%d from %p", row, column, window); |
| 336 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 337 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 338 | if (!fieldSlot) { |
| 339 | throwExceptionWithRowCol(env, row, column); |
| 340 | return; |
| 341 | } |
| 342 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 343 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 344 | if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 345 | size_t sizeIncludingNull; |
| 346 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 347 | if (sizeIncludingNull > 1) { |
| 348 | fillCharArrayBufferUTF(env, bufferObj, value, sizeIncludingNull - 1); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 349 | } else { |
| 350 | clearCharArrayBuffer(env, bufferObj); |
| 351 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 352 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 353 | int64_t value = window->getFieldSlotValueLong(fieldSlot); |
| 354 | char buf[32]; |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 355 | snprintf(buf, sizeof(buf), "%" PRId64, value); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 356 | fillCharArrayBufferUTF(env, bufferObj, buf, strlen(buf)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 357 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 358 | double value = window->getFieldSlotValueDouble(fieldSlot); |
| 359 | char buf[32]; |
| 360 | snprintf(buf, sizeof(buf), "%g", value); |
| 361 | fillCharArrayBufferUTF(env, bufferObj, buf, strlen(buf)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 362 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 363 | clearCharArrayBuffer(env, bufferObj); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 364 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 365 | throw_sqlite3_exception(env, "Unable to convert BLOB to string"); |
| 366 | } else { |
| 367 | throwUnknownTypeException(env, type); |
| 368 | } |
| 369 | } |
| 370 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 371 | static jlong nativeGetLong(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 372 | jint row, jint column) { |
| 373 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 374 | LOG_WINDOW("Getting long for %d,%d from %p", row, column, window); |
| 375 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 376 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 377 | if (!fieldSlot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | throwExceptionWithRowCol(env, row, column); |
| 379 | return 0; |
| 380 | } |
| 381 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 382 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 383 | if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 384 | return window->getFieldSlotValueLong(fieldSlot); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 385 | } else if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 386 | size_t sizeIncludingNull; |
| 387 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 388 | return sizeIncludingNull > 1 ? strtoll(value, NULL, 0) : 0L; |
| 389 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 390 | return jlong(window->getFieldSlotValueDouble(fieldSlot)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 391 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | return 0; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 393 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | throw_sqlite3_exception(env, "Unable to convert BLOB to long"); |
| 395 | return 0; |
| 396 | } else { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 397 | throwUnknownTypeException(env, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | } |
| 401 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 402 | static jdouble nativeGetDouble(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 403 | jint row, jint column) { |
| 404 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 405 | LOG_WINDOW("Getting double for %d,%d from %p", row, column, window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 407 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 408 | if (!fieldSlot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | throwExceptionWithRowCol(env, row, column); |
| 410 | return 0.0; |
| 411 | } |
| 412 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 413 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 414 | if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 415 | return window->getFieldSlotValueDouble(fieldSlot); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 416 | } else if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 417 | size_t sizeIncludingNull; |
| 418 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 419 | return sizeIncludingNull > 1 ? strtod(value, NULL) : 0.0; |
| 420 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 421 | return jdouble(window->getFieldSlotValueLong(fieldSlot)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 422 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | return 0.0; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 424 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | throw_sqlite3_exception(env, "Unable to convert BLOB to double"); |
| 426 | return 0.0; |
| 427 | } else { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 428 | throwUnknownTypeException(env, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | return 0.0; |
| 430 | } |
| 431 | } |
| 432 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 433 | static jboolean nativePutBlob(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 434 | jbyteArray valueObj, jint row, jint column) { |
| 435 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 436 | jsize len = env->GetArrayLength(valueObj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 438 | void* value = env->GetPrimitiveArrayCritical(valueObj, NULL); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 439 | status_t status = window->putBlob(row, column, value, len); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 440 | env->ReleasePrimitiveArrayCritical(valueObj, value, JNI_ABORT); |
| 441 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 442 | if (status) { |
| 443 | LOG_WINDOW("Failed to put blob. error=%d", status); |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | LOG_WINDOW("%d,%d is BLOB with %u bytes", row, column, len); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | return true; |
| 449 | } |
| 450 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 451 | static jboolean nativePutString(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 452 | jstring valueObj, jint row, jint column) { |
| 453 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 455 | size_t sizeIncludingNull = env->GetStringUTFLength(valueObj) + 1; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 456 | const char* valueStr = env->GetStringUTFChars(valueObj, NULL); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 457 | if (!valueStr) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 458 | LOG_WINDOW("value can't be transferred to UTFChars"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | return false; |
| 460 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 461 | status_t status = window->putString(row, column, valueStr, sizeIncludingNull); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 462 | env->ReleaseStringUTFChars(valueObj, valueStr); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 463 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 464 | if (status) { |
| 465 | LOG_WINDOW("Failed to put string. error=%d", status); |
| 466 | return false; |
| 467 | } |
| 468 | |
| 469 | LOG_WINDOW("%d,%d is TEXT with %u bytes", row, column, sizeIncludingNull); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | return true; |
| 471 | } |
| 472 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 473 | static jboolean nativePutLong(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 474 | jlong value, jint row, jint column) { |
| 475 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 476 | status_t status = window->putLong(row, column, value); |
| 477 | |
| 478 | if (status) { |
| 479 | LOG_WINDOW("Failed to put long. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | return false; |
| 481 | } |
| 482 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 483 | LOG_WINDOW("%d,%d is INTEGER 0x%016llx", row, column, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | return true; |
| 485 | } |
| 486 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 487 | static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 488 | jdouble value, jint row, jint column) { |
| 489 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 490 | status_t status = window->putDouble(row, column, value); |
| 491 | |
| 492 | if (status) { |
| 493 | LOG_WINDOW("Failed to put double. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | return false; |
| 495 | } |
| 496 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 497 | LOG_WINDOW("%d,%d is FLOAT %lf", row, column, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | return true; |
| 499 | } |
| 500 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 501 | static jboolean nativePutNull(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 502 | jint row, jint column) { |
| 503 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 504 | status_t status = window->putNull(row, column); |
| 505 | |
| 506 | if (status) { |
| 507 | LOG_WINDOW("Failed to put null. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 511 | LOG_WINDOW("%d,%d is NULL", row, column); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | return true; |
| 513 | } |
| 514 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 515 | static const JNINativeMethod sMethods[] = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 517 | /* name, signature, funcPtr */ |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 518 | { "nativeCreate", "(Ljava/lang/String;I)J", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 519 | (void*)nativeCreate }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 520 | { "nativeCreateFromParcel", "(Landroid/os/Parcel;)J", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 521 | (void*)nativeCreateFromParcel }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 522 | { "nativeDispose", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 523 | (void*)nativeDispose }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 524 | { "nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 525 | (void*)nativeWriteToParcel }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 526 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 527 | { "nativeGetName", "(J)Ljava/lang/String;", |
Jeff Brown | 650de3d | 2011-10-27 14:52:28 -0700 | [diff] [blame] | 528 | (void*)nativeGetName }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 529 | { "nativeGetBlob", "(JII)[B", |
| 530 | (void*)nativeGetBlob }, |
| 531 | { "nativeGetString", "(JII)Ljava/lang/String;", |
| 532 | (void*)nativeGetString }, |
| 533 | { "nativeCopyStringToBuffer", "(JIILandroid/database/CharArrayBuffer;)V", |
| 534 | (void*)nativeCopyStringToBuffer }, |
| 535 | { "nativePutBlob", "(J[BII)Z", |
| 536 | (void*)nativePutBlob }, |
| 537 | { "nativePutString", "(JLjava/lang/String;II)Z", |
| 538 | (void*)nativePutString }, |
| 539 | |
| 540 | // ------- @FastNative below here ---------------------- |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 541 | { "nativeClear", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 542 | (void*)nativeClear }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 543 | { "nativeGetNumRows", "(J)I", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 544 | (void*)nativeGetNumRows }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 545 | { "nativeSetNumColumns", "(JI)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 546 | (void*)nativeSetNumColumns }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 547 | { "nativeAllocRow", "(J)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 548 | (void*)nativeAllocRow }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 549 | { "nativeFreeLastRow", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 550 | (void*)nativeFreeLastRow }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 551 | { "nativeGetType", "(JII)I", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 552 | (void*)nativeGetType }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 553 | { "nativeGetLong", "(JII)J", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 554 | (void*)nativeGetLong }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 555 | { "nativeGetDouble", "(JII)D", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 556 | (void*)nativeGetDouble }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 557 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 558 | { "nativePutLong", "(JJII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 559 | (void*)nativePutLong }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 560 | { "nativePutDouble", "(JDII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 561 | (void*)nativePutDouble }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 562 | { "nativePutNull", "(JII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 563 | (void*)nativePutNull }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | }; |
| 565 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 566 | int register_android_database_CursorWindow(JNIEnv* env) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 568 | jclass clazz = FindClassOrDie(env, "android/database/CharArrayBuffer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 570 | gCharArrayBufferClassInfo.data = GetFieldIDOrDie(env, clazz, "data", "[C"); |
| 571 | gCharArrayBufferClassInfo.sizeCopied = GetFieldIDOrDie(env, clazz, "sizeCopied", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 573 | gEmptyString = MakeGlobalRefOrDie(env, env->NewStringUTF("")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 575 | return RegisterMethodsOrDie(env, "android/database/CursorWindow", sMethods, NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | } // namespace android |