/******************************************************** Table queries */ /** * Generate the <code>CREATE TABLE<code> query from a <code>PersistentEntity</code> class * @param domainClass the class of the persistent entity, must extends <code>PersistentEntity</code> * @return the generated <code>CREATE TABLE<code> query */ public static String CreateTableQuery(TableMapping <E> table) { ColumnInfo[] columns = table.columns; String sqlCreate = "CREATE TABLE IF NOT EXISTS " + table.name + " (" + Configuration.ID_COLUMN_NAME + " INTEGER PRIMARY KEY AUTOINCREMENT"; Type superClass = Reflections.GetBaseType(table.type); /*if (superClass != typeof(PersistentEntity)) { * //TODO: hay que ver en que orden se crean las clases y como corregir que la referencia no existe * //TODO: en principio esta resuelto con foreign_check = O; * sqlCreate += " REFERENCES " + superClass.Name + "(" + Configuration.ID_COLUMN_NAME + ") ON DELETE CASCADE"; * //TODO: esto lo hice por ON DELETE CASCADE pero no funciona :S * }*/ for (int i = 0; i < columns.Length; i++) { ColumnInfo column = columns[i]; if (!column.IsMultipleRelationship) { sqlCreate += ", " + ColumnDeclaration(column); } } sqlCreate += ");"; // TODO: Cuidado con estos replace que son solo esteticos y pueden joder la sentencia return(sqlCreate.Replace(" ", " ").Replace(" ,", ",")); }
public static String SelectQuery(TableMapping <E> table, String where) { return(SelectQuery(table, where, null, null, null, null, false)); }
public static String DeleteQuery(TableMapping <E> table, long id) { return("DELETE FROM " + table.name + " WHERE " + Configuration.ID_COLUMN_NAME + "=" + id); }
/** * Generate the <code>DROP TABLE<code> query from a <code>PersistentEntity</code> class * @param domainClass the class of the persistent entity, must extends <code>PersistentEntity</code> * @return the generated <code>DROP TABLE<code> query */ public static String DropTableQuery(TableMapping <E> table) { return("DROP TABLE IF EXISTS " + table.name); }