Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored and added support for splitting up tags.
- Loading branch information
1 parent
ac8cfc6
commit 9606388
Showing
9 changed files
with
5,802 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Data; | ||
using System.Xml; | ||
using System.Data.SqlClient; | ||
|
||
namespace SoSlow { | ||
|
||
|
||
delegate string ColumnValidator(string name, string value); | ||
|
||
class DumpReader : MinimalDataReader { | ||
|
||
DataTable schema; | ||
DataColumn nameColumn; | ||
ColumnValidator validator; | ||
XmlTextReader reader; | ||
|
||
public DumpReader(string filename, string target, SqlConnection connection, ColumnValidator validator) { | ||
using (var cmd = connection.CreateCommand()) { | ||
cmd.CommandType = CommandType.Text; | ||
cmd.CommandText = "select top 1 * from " + target; | ||
using (var reader = cmd.ExecuteReader()) { | ||
schema = reader.GetSchemaTable(); | ||
} | ||
} | ||
|
||
nameColumn = schema.Columns[0]; | ||
|
||
this.reader = new XmlTextReader(filename); | ||
this.validator = validator; | ||
} | ||
|
||
int rowNumber; | ||
public override bool Read() { | ||
rowNumber++; | ||
bool gotRow = false; | ||
while (reader.Read()) { | ||
if (reader.Name == "row") { | ||
gotRow = true; | ||
break; | ||
} | ||
} | ||
return gotRow; | ||
} | ||
|
||
public override void Dispose() { | ||
reader.Close(); | ||
} | ||
|
||
public override int FieldCount { | ||
get { return schema.Rows.Count; } | ||
} | ||
|
||
public override object GetValue(int i) { | ||
string name = (string)schema.Rows[i][nameColumn]; | ||
return ValidateOrDefault(name, reader.GetAttribute(name)); | ||
} | ||
|
||
private string ValidateOrDefault(string name, string data) { | ||
if (validator != null) { | ||
return validator(name, data); | ||
} | ||
return data; | ||
} | ||
|
||
public override DataTable GetSchemaTable() { | ||
return schema; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.