Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
[client][managed][offline] Speedup store table creation
Browse files Browse the repository at this point in the history
  • Loading branch information
hasankhan committed Nov 6, 2014
1 parent 5d7f502 commit eb7cc8d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,14 @@ private void CreateAllTables()

internal virtual void CreateTableFromObject(string tableName, IEnumerable<ColumnDefinition> columns)
{
String tblSql = string.Format("CREATE TABLE IF NOT EXISTS {0} ({1} PRIMARY KEY)", SqlHelpers.FormatTableName(tableName), SqlHelpers.FormatMember(MobileServiceSystemColumns.Id));
ColumnDefinition idColumn = columns.FirstOrDefault(c => c.Name.Equals(MobileServiceSystemColumns.Id));
var colDefinitions = columns.Where(c => c != idColumn).Select(c => String.Format("{0} {1}", SqlHelpers.FormatMember(c.Name), c.StoreType)).ToList();
if (idColumn != null)
{
colDefinitions.Insert(0, String.Format("{0} {1} PRIMARY KEY", SqlHelpers.FormatMember(idColumn.Name), idColumn.StoreType));
}

String tblSql = string.Format("CREATE TABLE IF NOT EXISTS {0} ({1})", SqlHelpers.FormatTableName(tableName), String.Join(", ", colDefinitions));
this.ExecuteNonQuery(tblSql, parameters: null);

string infoSql = string.Format("PRAGMA table_info({0});", SqlHelpers.FormatTableName(tableName));
Expand Down

0 comments on commit eb7cc8d

Please sign in to comment.