Собственно вот метод он содержится в пространстве имен ZennoLab.OwnCode
КАК его заблокировать для других потоков пока не выполню свой запрос к базе данных?
C#:
public class DB
{
private string hostname;
private string username;
private string password;
private string database;
private string timeout;
private string charset;
private string result;
private MySqlConnection conn;
public DB(string db_hostname, string db_username, string db_password, string db_database, string db_timeout, string db_charset="utf8"){
hostname = db_hostname;
username = db_username;
password = db_password;
database = db_database;
timeout = db_timeout;
charset = db_charset;
result = String.Empty;
string db_port = "3306";
var m = db_hostname.Split(':');
if ( m.Length == 2 ){
db_hostname = m[0];
db_port = m[1];
}
var connectionString = "server="+db_hostname+";user="+db_username+";database="+db_database+";port="+db_port+";password="+db_password+";defaultcommandtimeout="+db_timeout+";pooling=False;";
conn = new MySqlConnection(connectionString);
open();
}
public void open(){
conn.Open();
}
public void close(){
conn.Close();
}
public void query(string query){
MySqlCommand command = new MySqlCommand(query, conn);
command.ExecuteNonQuery();
}
public List<string> getAll(string query, string fieldSeparator="|"){
var result = new List<string>();
MySqlCommand command = new MySqlCommand(query, conn);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
List<string> fields = new List<string>();
for(int i=0; i<reader.FieldCount; i++)
fields.Add(reader[i].ToString());
result.Add(string.Join(fieldSeparator,fields));
}
reader.Close();
return result;
}
public List<string> getRow(string query){
MySqlCommand command = new MySqlCommand(query, conn);
MySqlDataReader reader = command.ExecuteReader();
if ( reader.Read() ){
List<string> result = new List<string>();
for(int i=0; i<reader.FieldCount; i++)
result.Add(reader[i].ToString());
reader.Close();
return result;
}
reader.Close();
return new List<string>();
}
public string getOne(string query){
MySqlCommand command = new MySqlCommand(query, conn);
string result = "";
try { result = command.ExecuteScalar().ToString(); } catch{}
return result;
}
public string escapeString(string text){
return MySql.Data.MySqlClient.MySqlHelper.EscapeString(text);
}
}