summaryrefslogtreecommitdiffstats
path: root/gallerycommon/src
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2012-05-04 18:07:48 +0800
committerHung-ying Tyan <tyanh@google.com>2012-05-04 18:08:42 +0800
commita67d89563df7c8847ee335723e097aaaffe43c36 (patch)
tree2b1111123a462c5ada81e31b2c75474d38345367 /gallerycommon/src
parentaa03cd0a539c56dcc0c6d2f9a000d8374b394b41 (diff)
downloadandroid_packages_apps_Snap-a67d89563df7c8847ee335723e097aaaffe43c36.tar.gz
android_packages_apps_Snap-a67d89563df7c8847ee335723e097aaaffe43c36.tar.bz2
android_packages_apps_Snap-a67d89563df7c8847ee335723e097aaaffe43c36.zip
Add UNIQUE to EntrySchema.
Change-Id: I0fbf69a60aafe8d7a82241467d077c48beadbf49
Diffstat (limited to 'gallerycommon/src')
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/Entry.java2
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/EntrySchema.java17
2 files changed, 17 insertions, 2 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/Entry.java b/gallerycommon/src/com/android/gallery3d/common/Entry.java
index b8cc51205..3f1644e65 100644
--- a/gallerycommon/src/com/android/gallery3d/common/Entry.java
+++ b/gallerycommon/src/com/android/gallery3d/common/Entry.java
@@ -48,6 +48,8 @@ public abstract class Entry {
boolean fullText() default false;
String defaultValue() default "";
+
+ boolean unique() default false;
}
public void clear() {
diff --git a/gallerycommon/src/com/android/gallery3d/common/EntrySchema.java b/gallerycommon/src/com/android/gallery3d/common/EntrySchema.java
index 46de03fd6..7bf7e431c 100644
--- a/gallerycommon/src/com/android/gallery3d/common/EntrySchema.java
+++ b/gallerycommon/src/com/android/gallery3d/common/EntrySchema.java
@@ -300,6 +300,7 @@ public final class EntrySchema {
StringBuilder sql = new StringBuilder("CREATE TABLE ");
sql.append(tableName);
sql.append(" (_id INTEGER PRIMARY KEY AUTOINCREMENT");
+ StringBuilder unique = new StringBuilder();
for (ColumnInfo column : mColumnInfo) {
if (!column.isId()) {
sql.append(',');
@@ -310,8 +311,18 @@ public final class EntrySchema {
sql.append(" DEFAULT ");
sql.append(column.defaultValue);
}
+ if (column.unique) {
+ if (unique.length() == 0) {
+ unique.append(column.name);
+ } else {
+ unique.append(',').append(column.name);
+ }
+ }
}
}
+ if (unique.length() > 0) {
+ sql.append(",UNIQUE(").append(unique).append(')');
+ }
sql.append(");");
logExecSql(db, sql.toString());
sql.setLength(0);
@@ -493,7 +504,7 @@ public final class EntrySchema {
// Add the column to the array.
int index = columns.size();
- columns.add(new ColumnInfo(info.value(), type, info.indexed(),
+ columns.add(new ColumnInfo(info.value(), type, info.indexed(), info.unique(),
info.fullText(), info.defaultValue(), field, index));
}
}
@@ -504,16 +515,18 @@ public final class EntrySchema {
public final String name;
public final int type;
public final boolean indexed;
+ public final boolean unique;
public final boolean fullText;
public final String defaultValue;
public final Field field;
public final int projectionIndex;
- public ColumnInfo(String name, int type, boolean indexed,
+ public ColumnInfo(String name, int type, boolean indexed, boolean unique,
boolean fullText, String defaultValue, Field field, int projectionIndex) {
this.name = name.toLowerCase();
this.type = type;
this.indexed = indexed;
+ this.unique = unique;
this.fullText = fullText;
this.defaultValue = defaultValue;
this.field = field;