コード例 #1
0
        public SQLiteDatabase(SQLiteCommand cmd, bool getTotalRowsForEachTable)
        {
            _name = cmd.Connection.FileName;

            _listTable    = new SQLiteTableList(cmd);
            _listSequence = new SQLiteSequenceList(cmd);
            _listIndex    = new SQLiteIndexList(cmd);
            var tables = _listTable.ToList();

            _listView    = new SQLiteViewList(cmd, tables);
            _listTrigger = new SQLiteTriggerList(cmd, tables, _listView.ToList());

            if (getTotalRowsForEachTable)
            {
                GetTotalRows(cmd);
            }
        }
コード例 #2
0
        internal void Export(List <string> tablesToExport, SQLiteTableList allTables,
                             SQLiteBackup manager)
        {
            if (_isProcessed || manager.stopProcess || !tablesToExport.Contains(_name.Trim().ToLower()))
            {
                return;
            }

            if (manager.ExportInfo.ExportTableStructure)
            {
                if (_dependancies.Count > 0)
                {
                    foreach (var dependantTable in _dependancies)
                    {
                        if (!tablesToExport.Contains(dependantTable))
                        {
                            throw new Exception(string.Format("Table \"{0}\" depends on table \"{1}\" via foreign key. However the latter is not included within exported table list.",
                                                              _name, dependantTable));
                        }
                    }
                    foreach (var dependantTable in _dependancies)
                    {
                        allTables[dependantTable].Export(tablesToExport, allTables, manager);
                    }
                }

                manager._currentTableName        = _name;
                manager._currentTableIndex       = allTables.IndexOf(this);
                manager._totalRowsInCurrentTable = _totalRows;

                manager.Export_WriteComment("");
                manager.Export_WriteComment(string.Format("Definition of {0}", _name));
                manager.Export_WriteComment("");

                manager.textWriter.WriteLine();

                manager.Export_WriteLine(string.Format("DROP TABLE IF EXISTS `{0}`;", _name));

                manager.Export_WriteLine(_createTableSql);

                manager.textWriter.WriteLine();

                manager.textWriter.Flush();
            }

            if (manager.ExportInfo.ExportRows)
            {
                manager.Export_WriteComment("");
                manager.Export_WriteComment(string.Format("Dumping data for table {0}", _name));
                manager.Export_WriteComment("");
                manager.textWriter.WriteLine();

                manager._currentRowIndexInCurrentTable = 0L;

                if (manager.ExportInfo.RowsExportMode == RowsDataExportMode.Insert ||
                    manager.ExportInfo.RowsExportMode == RowsDataExportMode.InsertIgnore ||
                    manager.ExportInfo.RowsExportMode == RowsDataExportMode.Replace)
                {
                    Export_RowsData_Insert_Ignore_Replace(manager);
                }
                else if (manager.ExportInfo.RowsExportMode == RowsDataExportMode.OnDuplicateKeyUpdate)
                {
                    Export_RowsData_OnDuplicateKeyUpdate(manager);
                }
                else if (manager.ExportInfo.RowsExportMode == RowsDataExportMode.Update)
                {
                    Export_RowsData_Update(manager);
                }

                manager.textWriter.WriteLine();
                manager.textWriter.Flush();
            }

            _isProcessed = true;
        }