From eb7cc8d2792589e0fb39328b880957f9e53ae59a Mon Sep 17 00:00:00 2001 From: Hasan Khan Date: Thu, 6 Nov 2014 11:13:41 -0800 Subject: [PATCH] [client][managed][offline] Speedup store table creation --- .../MobileServiceSQLiteStore.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices.SQLiteStore/MobileServiceSQLiteStore.cs b/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices.SQLiteStore/MobileServiceSQLiteStore.cs index 6bbd59eb0..b0b2fefee 100644 --- a/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices.SQLiteStore/MobileServiceSQLiteStore.cs +++ b/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices.SQLiteStore/MobileServiceSQLiteStore.cs @@ -375,7 +375,14 @@ private void CreateAllTables() internal virtual void CreateTableFromObject(string tableName, IEnumerable 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));