summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorVasu Nori <vnori@google.com>2010-01-29 16:24:23 -0800
committerVasu Nori <vnori@google.com>2010-02-01 23:05:33 -0800
commit4dd4ab4cc322e82401f380aeb877daa4a20d7069 (patch)
treea8391213899cdbe298b446502d7430e3327fe5d1 /core/tests
parent6eb7c45a8fdb774c4094b5012c8496f2a009c032 (diff)
downloadframeworks_base-4dd4ab4cc322e82401f380aeb877daa4a20d7069.zip
frameworks_base-4dd4ab4cc322e82401f380aeb877daa4a20d7069.tar.gz
frameworks_base-4dd4ab4cc322e82401f380aeb877daa4a20d7069.tar.bz2
add instrumentation to log the sql statement + bindargs + databasename
capture the sql statement along with the bindargs passed in. this will help one to see the sql statements being executed and hopefully will help debug incorrect-sql bugs.
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/coretests/src/android/database/sqlite/SQLiteDebugTest.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/database/sqlite/SQLiteDebugTest.java b/core/tests/coretests/src/android/database/sqlite/SQLiteDebugTest.java
new file mode 100644
index 0000000..ea807bd
--- /dev/null
+++ b/core/tests/coretests/src/android/database/sqlite/SQLiteDebugTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.database.sqlite;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the SQLiteDebug
+ */
+public class SQLiteDebugTest extends TestCase {
+ private static final String TEST_DB = "test.db";
+
+ public void testCaptureSql() {
+ String rslt = SQLiteDebug.captureSql(TEST_DB, "select * from t1 where a=? and b=1",
+ new Object[] {"blah"});
+ String expectedVal = "select * from t1 where a='blah' and b=1";
+ assertTrue(rslt.equals("captured_sql|" + TEST_DB + "|" + expectedVal));
+
+ rslt = SQLiteDebug.captureSql(TEST_DB, "select * from t1 where a=?",
+ new Object[] {"blah"});
+ expectedVal = "select * from t1 where a='blah'";
+ assertTrue(rslt.equals("captured_sql|" + TEST_DB + "|" + expectedVal));
+
+ rslt = SQLiteDebug.captureSql(TEST_DB, "select * from t1 where a=1",
+ new Object[] {"blah"});
+ assertTrue(rslt.startsWith("too many bindArgs provided."));
+
+ rslt = SQLiteDebug.captureSql(TEST_DB, "update t1 set a=? where b=?",
+ new Object[] {"blah", "foo"});
+ expectedVal = "update t1 set a='blah' where b='foo'";
+ assertTrue(rslt.equals("captured_sql|" + TEST_DB + "|" + expectedVal));
+ }
+}