Esempio n. 1
0
        private static void updateToVersion(DataTable dataTable, SQLiteDatabase db, int originalVersion,
                                            int updateVersion, Dictionary <string, string> tempMap, List <string> currentTables, List <TableBase> AllTables)
        {
            TableMapList mapList = buildMap(dataTable, originalVersion, updateVersion, tempMap, currentTables);

            foreach (TableMap map in mapList)
            {
                if (isSingleRow(map))
                {
                    DataTable dt            = combinedTable(map, db);
                    string    insertColumns = DatabaseHelper.FieldsString(map.UpdateFields);
                    foreach (DataRow row in dt.Rows)
                    {
                        List <string> values = new List <string>();
                        foreach (var field in map.OriginalFields)
                        {
                            values.Add(row[field].ToString());
                        }
                        string insertValues = DatabaseHelper.ValuesString(values);
                        string command      = String.Format("insert into {0} ({1}) values ({2})", map.UpdateTableName, insertColumns, insertValues);
                        db.NonQueryCommand(command);
                    }
                }
                else
                {
                    foreach (string table in map.OriginalTableNames)
                    {
                        migrateData(table, DatabaseHelper.FieldsString(map.TableFieldsDictionary[table]),
                                    map.UpdateTableName, DatabaseHelper.FieldsString(map.UpdateFields), db);
                    }
                }

                foreach (TableBase table in AllTables)
                {
                    if (tempMap[table.NameString] == map.UpdateTableName)
                    {
                        foreach (TableField field in table.Fields)
                        {
                            if (!map.UpdateFields.Contains(field.Name))
                            {
                                string command = String.Format("update {0} set {1} = \'{2}\' ",
                                                               tempMap[table.NameString], field.Name, field.DefaultValue);
                                db.NonQueryCommand(command);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static TableMapList buildMap(DataTable versionData, int originalVersion,
                                             int updateVersion, Dictionary <string, string> tempMap, List <string> currentTables)
        {
            string originalTableColumn = tableString(originalVersion);
            string originalFieldColumn = fieldString(originalVersion);
            string updateTableColumn   = tableString(updateVersion);
            string updateFieldColumn   = fieldString(updateVersion);

            TableMapList mapList = new TableMapList();

            foreach (DataRow row in versionData.Rows)
            {
                if (tempMap.ContainsKey(row[updateTableColumn].ToString()) && currentTables.Contains(row[originalTableColumn]))
                {
                    string originalTable   = row[originalTableColumn].ToString();
                    string originalField   = originalTable + "." + row[originalFieldColumn].ToString();
                    string updateTempTable = tempMap[row[updateTableColumn].ToString()];
                    string updateField     = row[updateFieldColumn].ToString();

                    if (row[originalFieldColumn].ToString() != "NONE" || row[updateFieldColumn].ToString() != "NONE")
                    {
                        if (mapList.ContainsTable(updateTempTable))
                        {
                            TableMap map = mapList.GetMap(updateTempTable);
                            map.Add(originalTable, originalField, updateField);
                        }
                        else
                        {
                            TableMap map = new TableMap(updateTempTable);
                            map.Add(originalTable, originalField, updateField);
                            mapList.Add(map);
                        }
                    }
                }
            }
            return(mapList);
        }