aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLFramework.cs
diff options
context:
space:
mode:
authoronefang2019-09-11 16:36:50 +1000
committeronefang2019-09-11 16:36:50 +1000
commit50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch)
tree52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Data/MySQL/MySQLFramework.cs
parentRenamed branch to SledjChisl. (diff)
parentBump to release flavour, build 0. (diff)
downloadopensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLFramework.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLFramework.cs60
1 files changed, 54 insertions, 6 deletions
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index 5820a90..98106f0 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -36,7 +36,7 @@ using MySql.Data.MySqlClient;
36namespace OpenSim.Data.MySQL 36namespace OpenSim.Data.MySQL
37{ 37{
38 /// <summary> 38 /// <summary>
39 /// A database interface class to a user profile storage system 39 /// Common code for a number of database modules
40 /// </summary> 40 /// </summary>
41 public class MySqlFramework 41 public class MySqlFramework
42 { 42 {
@@ -44,30 +44,78 @@ namespace OpenSim.Data.MySQL
44 log4net.LogManager.GetLogger( 44 log4net.LogManager.GetLogger(
45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected string m_connectionString; 47 protected string m_connectionString = String.Empty;
48 protected MySqlTransaction m_trans = null;
48 49
50 // Constructor using a connection string. Instances constructed
51 // this way will open a new connection for each call.
49 protected MySqlFramework(string connectionString) 52 protected MySqlFramework(string connectionString)
50 { 53 {
51 m_connectionString = connectionString; 54 m_connectionString = connectionString;
52 } 55 }
53 56
57 // Constructor using a connection object. Instances constructed
58 // this way will use the connection object and never create
59 // new connections.
60 protected MySqlFramework(MySqlTransaction trans)
61 {
62 m_trans = trans;
63 }
64
65 //////////////////////////////////////////////////////////////
66 //
67 // All non queries are funneled through one connection
68 // to increase performance a little
69 //
54 protected int ExecuteNonQuery(MySqlCommand cmd) 70 protected int ExecuteNonQuery(MySqlCommand cmd)
55 { 71 {
56 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 72 if (m_trans == null)
73 {
74 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
75 {
76 dbcon.Open();
77 int ret = ExecuteNonQueryWithConnection(cmd, dbcon);
78 dbcon.Close();
79 return ret;
80 }
81 }
82 else
83 {
84 return ExecuteNonQueryWithTransaction(cmd, m_trans);
85 }
86 }
87
88 private int ExecuteNonQueryWithTransaction(MySqlCommand cmd, MySqlTransaction trans)
89 {
90 cmd.Transaction = trans;
91 return ExecuteNonQueryWithConnection(cmd, trans.Connection);
92 }
93
94 private int ExecuteNonQueryWithConnection(MySqlCommand cmd, MySqlConnection dbcon)
95 {
96 try
57 { 97 {
58 dbcon.Open();
59 cmd.Connection = dbcon; 98 cmd.Connection = dbcon;
60 99
61 try 100 try
62 { 101 {
63 return cmd.ExecuteNonQuery(); 102 int ret = cmd.ExecuteNonQuery();
103 cmd.Connection = null;
104 return ret;
64 } 105 }
65 catch (Exception e) 106 catch (Exception e)
66 { 107 {
67 m_log.Error(e.Message, e); 108 m_log.Error(e.Message, e);
109 m_log.Error(Environment.StackTrace.ToString());
110 cmd.Connection = null;
68 return 0; 111 return 0;
69 } 112 }
70 } 113 }
114 catch (Exception e)
115 {
116 m_log.Error(e.Message, e);
117 return 0;
118 }
71 } 119 }
72 } 120 }
73} \ No newline at end of file 121}