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