/// <summary> /// Exporta as tabelas existentes no database para arquivos XML, os dados são gravados no XML em /// formato pronto para INSERT (sem informação de tipo porém no formato esperado pelo BD) /// </summary> public Boolean DBExport(String databaseName) { if (!OpenConnection()) { return(false); } currentDatabase = databaseName; decimalSeparatorIsComma = FieldParser.IsCommaDecimalSeparator(); DBQuery dbQuery = new DBQuery(sqlConnection); dbQuery.Query = "use " + currentDatabase; dbQuery.Execute(false); dbQuery.Query = "SELECT name, id FROM sysObjects WHERE xtype = 'U'"; dbQuery.Execute(true); List <Object> tableList = dbQuery.ExtractFromResultset(typeof(DBObject)); if (tableList.Count < 1) { CloseConnection(); return(false); } foreach (DBObject table in tableList) { // Verifica a quantidade de registros da tabela dbQuery.Query = "SELECT COUNT(1) FROM " + table.name; dbQuery.Execute(true); int?rowCount = dbQuery.ExtractFromResultset(); if (rowCount > 1000000) { continue; // Pula tabelas com mais de 1 milhão de registros ( backup manual ) } dbQuery.Query = "SELECT name FROM sysColumns WHERE id = " + table.id; dbQuery.Execute(true); List <Object> fieldList = dbQuery.ExtractFromResultset(new String[] { "name" }); String[] fieldNames = new String[fieldList.Count]; for (int index = 0; index < fieldList.Count; index++) { fieldNames[index] = (String)((Object[])fieldList[index])[0]; } dbQuery.Query = "SELECT * FROM " + table.name; dbQuery.Execute(true); List <Object> rowList = dbQuery.ExtractFromResultset(fieldNames); Boolean tableExported = ExportTable(table.name, fieldNames, rowList); if (!tableExported) { CloseConnection(); return(false); } } CloseConnection(); return(true); }
/// <summary> /// Cria a tabela que receberá os dados do relatório, no .CSV apenas separa os nomes das /// colunas pois essa tabela não existe fisicamente /// </summary> public void CreateDataTable(String[] columnNames, int[] columnWidths, int rowCount) { // Grava os comentários no arquivo // streamWriter.WriteLine(csvComment); removi para facilitar importação no excel // Grava os nomes das colunas no arquivo String columnList = null; for (int ndx = 0; ndx < columnNames.Length; ndx++) { if (!String.IsNullOrEmpty(columnList)) { columnList += ","; } columnList += columnNames[ndx]; } streamWriter.WriteLine(columnList); // Verifica o separador decimal, para depois não misturar com as virgulas que separam os campos do CSV decimalSeparatorIsComma = FieldParser.IsCommaDecimalSeparator(); // Cria o totalizador totalizer = new ReportTotalizer(columnNames.Length); }