public bool CreateGeographiesTable(DbConnection conn)
{
//create the table
string createGeographyTableSQL = DataClient.GenerateTableSQLFromFields(
this.GetGeographyTablename(),
GeographyFileReader.Columns);
DbClient.GetCommand(createGeographyTableSQL, conn).ExecuteNonQuery();
//parse in the file
string geographyFilename = GetLocalGeographyFileName();
GeographyFileReader geoReader = new GeographyFileReader(geographyFilename);
if (geoReader.HasFile)
{
_log.Debug("Importing Geographies File...");
string tableSelect = string.Format("select * from \"{0}\"", this.GetGeographyTablename());
var adapter = DataClient.GetMagicAdapter(conn, DbClient, tableSelect);
var table = DataClient.GetMagicTable(conn, DbClient, tableSelect);
_log.Debug("Reading...");
int primKey = 0;
foreach (List<string> row in geoReader.GetReader())
{
var geoData = row.ToArray();
//add a primary key on there
object[] rowData = new object[table.Columns.Count];
rowData[0] = primKey++;
Array.Copy(geoData, 0, rowData, 1, geoData.Length);
table.Rows.Add(rowData);
}
if ((table != null) && (table.Rows.Count > 0))
{
_log.Debug("Saving... (This can take a while)");
//this.StateFIPS = (table.Rows[0]["STATE"] as string);
adapter.Update(table);
table.AcceptChanges();
}
_log.Debug("Importing Geographies File... Done!");
return true;
}
else
{
_log.Debug("Could not find geographies file, table could not be initialized!");
return false;
}
}