package sword.langbook3.android.sqlite;

import sword.database.DbColumn;
import sword.database.DbValue;

public final class SqliteUtils {

    private SqliteUtils() {
    }

    public static String sqlType(DbColumn column) {
        if (column.isPrimaryKey()) {
            return "INTEGER PRIMARY KEY AUTOINCREMENT";
        }
        else if (column.isUnique()) {
            return "TEXT UNIQUE ON CONFLICT IGNORE";
        }
        else if (column.isText()) {
            return "TEXT";
        }
        else {
            return "INTEGER";
        }
    }

    public static String sqlValue(DbValue value) {
        return value.isText()? "'" + value.toText() + '\'' : Integer.toString(value.toInt());
    }
}

@@ -339,83 +339,80 @@
 lse 
-if (column.isUnique()) %7B%0A            return %22TEXT UNIQUE ON CONFLICT IGNORE
+%7B%0A            final String typeName = column.isText()? %22TEXT%22 : %22INTEGER
 %22;%0A 
@@ -420,128 +420,90 @@
     
-  %7D%0A
       
-  else if (column.isText()) %7B%0A            return %22TEXT%22;%0A        %7D%0A        else %7B%0A            return %22INTEGER%22
+return column.isUnique()? typeName + %22 UNIQUE ON CONFLICT IGNORE%22 : typeName
 ;%0A  

Allow having unique integer columns in the database