/// <summary> /// Stores the terrain map to DB. /// </summary> /// <param name="terrain">terrain map data.</param> /// <param name="regionID">regionID.</param> public void StoreTerrain(HeightMapTerrainData terrData, UUID regionID) { //Delete old terrain map string sql = "delete from terrain where RegionUUID=@RegionUUID"; using (SqlConnection conn = new SqlConnection(m_connectionString)) using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); conn.Open(); cmd.ExecuteNonQuery(); } sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; int terrainDBRevision; Array terrainDBblob; terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); using (SqlConnection conn = new SqlConnection(m_connectionString)) { using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision)); cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob)); conn.Open(); cmd.ExecuteNonQuery(); } } _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision); }
/// <summary> /// Stores the terrain map to DB. /// </summary> /// <param name="terrain">terrain map data.</param> /// <param name="regionID">regionID.</param> public void StoreTerrain(HeightMapTerrainData terrData, UUID regionID) { //Delete old terrain map string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID"; using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) { using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) { cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); conn.Open(); cmd.ExecuteNonQuery(); _Log.InfoFormat("{0} Deleted terrain revision id = {1}", LogHeader, regionID); } } int terrainDBRevision; Array terrainDBblob; terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)"; using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) { using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) { cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision)); cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob)); conn.Open(); cmd.ExecuteNonQuery(); _Log.InfoFormat("{0} Stored terrain id = {1}, terrainSize = <{2},{3}>", LogHeader, regionID, terrData.SizeX, terrData.SizeY); } } }
/// <summary> /// Store a terrain revision in region storage /// </summary> /// <param name="ter">terrain heightfield</param> /// <param name="regionID">region UUID</param> public void StoreTerrain(HeightMapTerrainData terrData, UUID regionID) { lock (this) { using ( SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn)) { cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); cmd.ExecuteNonQuery(); } // the following is an work around for .NET. The perf // issues associated with it aren't as bad as you think. String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + " values(:RegionUUID, :Revision, :Heightfield)"; int terrainDBRevision; Array terrainDBblob; terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision); using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) { cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision)); cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob)); cmd.ExecuteNonQuery(); } } }
public void StoreTerrain(HeightMapTerrainData terrData, UUID regionID) { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); using (MySqlCommand cmd = dbcon.CreateCommand()) { cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID"; cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString()); ExecuteNonQuery(cmd); int terrainDBRevision; Array terrainDBblob; terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}", LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision); cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)" + "values (?RegionUUID, ?Revision, ?Heightfield)"; cmd.Parameters.AddWithValue("Revision", terrainDBRevision); cmd.Parameters.AddWithValue("Heightfield", terrainDBblob); ExecuteNonQuery(cmd); } } }