本文整理汇总了C#中DBConnector.TransCommit方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnector.TransCommit方法的具体用法?C# DBConnector.TransCommit怎么用?C# DBConnector.TransCommit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnector
的用法示例。
在下文中一共展示了DBConnector.TransCommit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportCommodities
/// <summary>
/// imports the data from the list
/// (only newer data will be imported)
/// </summary>
/// <param name="fileName"></param>
internal void ImportCommodities(List<EDCommodities> Commodities)
{
String sqlString;
Int32 Counter = 0;
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
try
{
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin();
sendProgressEvent(new ProgressEventArgs() { Info="import commodities", CurrentValue=0, TotalValue=Commodities.Count });
// insert or update all commodities
foreach (EDCommodities Commodity in Commodities)
{
sqlString = "insert into tbCategory(id, category, loccategory) values (" +
Commodity.Category.Id.ToString() + "," +
SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) + "," +
SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) +
") ON DUPLICATE KEY UPDATE " +
"category = " + SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) + "," +
"loccategory = " + SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString());
lDBCon.Execute(sqlString);
sqlString = "insert into tbCommodity(id, commodity, loccommodity, category_id, average_price) values (" +
Commodity.Id.ToString() + "," +
SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
Commodity.CategoryId.ToString() + "," +
DBConvert.ToString(Commodity.AveragePrice) +
") ON DUPLICATE KEY UPDATE " +
"commodity = " + SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
"loccommodity = " + SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
"category_id = " + Commodity.CategoryId.ToString() + "," +
"average_price = " + DBConvert.ToString(Commodity.AveragePrice);
lDBCon.Execute(sqlString);
Counter++;
if(sendProgressEvent(new ProgressEventArgs() { Info="import commodities", CurrentValue=Counter, TotalValue=Commodities.Count }))
break;
}
lDBCon.TransCommit();
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon.TransActive())
lDBCon.TransRollback();
try
{
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception) { }
throw new Exception("Error while importing system data", ex);
}
}
示例2: ImportVisitedStations
/// <summary>
/// imports the old list of visited stations to the database
/// </summary>
/// <param name="StationObject"></param>
/// <param name="EconomyRow"></param>
public void ImportVisitedStations(string Filename)
{
String sqlString;
Int32 Counter = 0;
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
try
{
List<StationVisit> History = JsonConvert.DeserializeObject<List<StationVisit>>(File.ReadAllText(Filename));
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin("ImportVisitedStations");
sendProgressEvent(new ProgressEventArgs() { Info="import visited stations", CurrentValue=Counter, TotalValue=History.Count });
foreach(StationVisit VisitEvent in History)
{
String System = StructureHelper.CombinedNameToSystemName(VisitEvent.Station);
String Station = StructureHelper.CombinedNameToStationName(VisitEvent.Station);
//Debug.Print(System + "," + Location);
try
{
sqlString = String.Format("insert ignore into tbVisitedSystems(system_id, time)" +
" SELECT d.* FROM (SELECT" +
" (select id from tbSystems where systemname = {0}) as system_id," +
" {1} as time) as d",
DBConnector.SQLAString(DBConnector.SQLEscape(System)),
DBConnector.SQLDateTime(VisitEvent.Visited));
lDBCon.Execute(sqlString);
}
catch (Exception)
{
//Debug.Print("Error while importing system in history :" + System);
};
try
{
sqlString = String.Format("insert ignore into tbVisitedStations(station_id, time)" +
" SELECT d.* FROM (SELECT" +
" (select id from tbStations" +
" where stationname = {0}" +
" and system_id = (select id from tbSystems where systemname = {1})) as station_id," +
" {2} as time) as d",
DBConnector.SQLAString(DBConnector.SQLEscape(Station)),
DBConnector.SQLAString(DBConnector.SQLEscape(System)),
DBConnector.SQLDateTime(VisitEvent.Visited));
lDBCon.Execute(sqlString);
}
catch (Exception)
{
//Debug.Print("Error while importing station in history :" + Location);
};
Counter++;
sendProgressEvent(new ProgressEventArgs() { Info="import visited stations", CurrentValue=Counter, TotalValue=History.Count });
}
lDBCon.TransCommit();
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon.TransActive())
lDBCon.TransRollback();
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
throw new Exception("Error while importing the history of visited stations", ex);
}
}
示例3: ImportStations
//.........这里部分代码省略.........
// self-created stations don't have the correct id so they must be identified by name
FoundRows = (dsEliteDB.tbstationsRow[])Data.tbstations.Select("stationname = " + DBConnector.SQLAString(DBConnector.DTEscape(Station.Name.ToString())) + " and " +
" system_id = " + Station.SystemId + " and " +
" id < 0");
if (FoundRows.Count() > 0)
{
// self created station is existing -> correct id and get new data from EDDB
CopyEDStationToDataRow(Station, (DataRow)FoundRows[0], false, null, true);
// update immediately because otherwise the references are wrong after changing a id
lDBCon.TableUpdate(Data.tbstations);
lDBCon.TableUpdate(Data.tbstations_org);
lDBCon.TableUpdate(Data.tbstationeconomy);
lDBCon.TableUpdate(Data.tbcommodityclassification);
lDBCon.TableUpdate(Data.tbcommodity_has_attribute);
lDBCon.TableUpdate(Data.tbattribute);
lDBCon.TableRefresh(Data.tbstationeconomy);
lDBCon.TableRefresh(Data.tbcommodityclassification);
lDBCon.TableRefresh(Data.tbcommodity_has_attribute);
lDBCon.TableRefresh(Data.tbattribute);
}
else
{
// add a new Location
dsEliteDB.tbstationsRow newStationRow = (dsEliteDB.tbstationsRow)Data.tbstations.NewRow();
CopyEDStationToDataRow(Station, (DataRow)newStationRow, false, null, true);
Data.tbstations.Rows.Add(newStationRow);
added++;
}
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
CopyEDStationCommodityToDataRow(Station, Data, ref currentComodityClassificationID);
ImportCounter += 1;
}
if ((ImportCounter > 0) && ((ImportCounter % 100) == 0))
{
// save changes
Debug.Print("added Stations : " + ImportCounter.ToString());
lDBCon.TableUpdate(Data.tbstations);
lDBCon.TableUpdate(Data.tbstations_org);
lDBCon.TableUpdate(Data.tbstationeconomy);
lDBCon.TableUpdate(Data.tbcommodityclassification);
lDBCon.TableUpdate(Data.tbcommodity_has_attribute);
lDBCon.TableUpdate(Data.tbattribute);
}
Counter++;
if(sendProgressEvent(new ProgressEventArgs() { Info = String.Format("import stations : analysed={0}, updated={1}, added={2}", Counter, ImportCounter-added, added), CurrentValue=Counter, TotalValue=Stations.Count}))
break;
}
// save changes
lDBCon.TableUpdate(Data.tbstations);
lDBCon.TableUpdate(Data.tbstations_org);
lDBCon.TableUpdate(Data.tbstationeconomy);
lDBCon.TableUpdate(Data.tbcommodityclassification);
lDBCon.TableUpdate(Data.tbcommodity_has_attribute);
lDBCon.TableUpdate(Data.tbattribute);
lDBCon.TransCommit();
// now add the prices if wanted
if (addPrices)
{
ImportPrices(Stations, enImportBehaviour.OnlyNewer, enDataSource.fromEDDN);
}
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon != null)
{
if (lDBCon.TransActive())
lDBCon.TransRollback();
try
{
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception) { }
}
throw new Exception("Error while importing Station data", ex);
}
}
示例4: ImportStations_Own
//.........这里部分代码省略.........
{
// data from file is newer
CopyEDStationToDataRow(Station, (DataRow)FoundRows[0], true, null, true);
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
// commodities are not considered because there was no possibility for input in the old RN
ImportCounter += 1;
}
}
else
{
// new data is user changed data, old data is original data
// copy the original data ("tbStations") to the saving data table ("tbStations_org")
// and get the correct system ID
Data.tbstations_org.LoadDataRow(FoundRows[0].ItemArray, false);
CopyEDStationToDataRow(Station, (DataRow)FoundRows[0], true, null, true);
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
// commodities are not considered because there was no possibility for input in the old RN
ImportCounter += 1;
}
}
}
else
{
// add a new station
Station.Id = currentSelfCreatedIndex;
dsEliteDB.tbstationsRow newRow = (dsEliteDB.tbstationsRow)Data.tbstations.NewRow();
CopyEDStationToDataRow(Station, (DataRow)newRow, true, null, true);
newRow.visited = setVisitedFlag;
newRow.updated_at = DateTime.UtcNow;
Data.tbstations.Rows.Add(newRow);
currentSelfCreatedIndex -= 1;
ImportCounter += 1;
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
// commodities are not considered because there was no possibility for input in the old RN
ImportCounter += 1;
}
if ((ImportCounter > 0) && ((ImportCounter % 100) == 0))
{
// save changes
Debug.Print("added Stations : " + ImportCounter.ToString());
lDBCon.TableUpdate(Data.tbstations);
lDBCon.TableUpdate(Data.tbstations_org);
lDBCon.TableUpdate(Data.tbstationeconomy);
}
}
else
Debug.Print("why");
Counter++;
sendProgressEvent(new ProgressEventArgs() { Info="import self-added stations", CurrentValue=Counter, TotalValue=Stations.Count });
}
// save changes
lDBCon.TableUpdate(Data.tbstations);
lDBCon.TableUpdate(Data.tbstations_org);
lDBCon.TableUpdate(Data.tbstationeconomy);
lDBCon.TransCommit();
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon != null)
{
if (lDBCon.TransActive())
lDBCon.TransRollback();
try
{
lDBCon.Dispose();
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception) { }
}
throw new Exception("Error while importing Station data", ex);
}
}
示例5: ImportSystems_Own
//.........这里部分代码省略.........
{
// old data is changed by user and the new data is also a user changed data
// keep the newer version in the main table
Timestamp_old = (DateTime)(FoundRows[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(System.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer -> take it but hold the old id
CopyEDSystemToDataRow(System, (DataRow)FoundRows[0], true, null, true);
ImportCounter += 1;
}
}
else
{
// new data is user changed data, old data is original data
// copy the original data ("tbSystems") to the saving data table ("tbSystems_org")
// and get the correct system ID
Data.tbsystems_org.LoadDataRow(FoundRows[0].ItemArray, false);
CopyEDSystemToDataRow(System, (DataRow)FoundRows[0], true, null, true);
ImportCounter += 1;
}
}
else
{
System.Id = (Int32)FoundRows[0]["id"];
}
}
else
{
// add a new system
// memorize the changed system ids for importing user changed stations in the (recommend) second step
if (!OnlyAddUnknown)
changedSystemIDs.Add(System.Id, currentSelfCreatedIndex);
System.Id = currentSelfCreatedIndex;
dsEliteDB.tbsystemsRow newRow = (dsEliteDB.tbsystemsRow)Data.tbsystems.NewRow();
CopyEDSystemToDataRow(System, (DataRow)newRow, true, null, true);
newRow.visited = setVisitedFlag;
newRow.updated_at = DateTime.UtcNow;
Data.tbsystems.Rows.Add(newRow);
currentSelfCreatedIndex -= 1;
ImportCounter += 1;
}
if ((ImportCounter > 0) && ((ImportCounter % 100) == 0))
{
// save changes
Debug.Print("added Systems : " + ImportCounter.ToString());
lDBCon.TableUpdate(Data.tbsystems);
lDBCon.TableUpdate(Data.tbsystems_org);
}
}
Counter++;
sendProgressEvent(new ProgressEventArgs() { Info="import self-added systems", CurrentValue=Counter, TotalValue=Systems.Count });
}
// save changes
lDBCon.TableUpdate(Data.tbsystems);
lDBCon.TableUpdate(Data.tbsystems_org);
lDBCon.TransCommit();
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
// return all changed ids
return changedSystemIDs;
}
catch (Exception ex)
{
if(lDBCon != null)
{
if (lDBCon.TransActive())
lDBCon.TransRollback();
try
{
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception)
{ }
}
throw new Exception("Error while importing system data", ex);
}
}