build const strings a compile time...

httptests
UbitUmarov 2017-05-06 20:23:55 +01:00
parent 54eb6fc779
commit 504736eb43
1 changed files with 146 additions and 201 deletions

View File

@ -90,7 +90,7 @@ namespace OpenSim.Data.MySQL
using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
{ {
string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id"; const string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id";
dbcon.Open(); dbcon.Open();
using (MySqlCommand cmd = new MySqlCommand(query, dbcon)) using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
{ {
@ -129,52 +129,51 @@ namespace OpenSim.Data.MySQL
public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result) public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
{ {
string query = string.Empty; const string query =
"INSERT INTO classifieds ("
+ "`classifieduuid`,"
query += "INSERT INTO classifieds ("; + "`creatoruuid`,"
query += "`classifieduuid`,"; + "`creationdate`,"
query += "`creatoruuid`,"; + "`expirationdate`,"
query += "`creationdate`,"; + "`category`,"
query += "`expirationdate`,"; + "`name`,"
query += "`category`,"; + "`description`,"
query += "`name`,"; + "`parceluuid`,"
query += "`description`,"; + "`parentestate`,"
query += "`parceluuid`,"; + "`snapshotuuid`,"
query += "`parentestate`,"; + "`simname`,"
query += "`snapshotuuid`,"; + "`posglobal`,"
query += "`simname`,"; + "`parcelname`,"
query += "`posglobal`,"; + "`classifiedflags`,"
query += "`parcelname`,"; + "`priceforlisting`) "
query += "`classifiedflags`,"; + "VALUES ("
query += "`priceforlisting`) "; + "?ClassifiedId,"
query += "VALUES ("; + "?CreatorId,"
query += "?ClassifiedId,"; + "?CreatedDate,"
query += "?CreatorId,"; + "?ExpirationDate,"
query += "?CreatedDate,"; + "?Category,"
query += "?ExpirationDate,"; + "?Name,"
query += "?Category,"; + "?Description,"
query += "?Name,"; + "?ParcelId,"
query += "?Description,"; + "?ParentEstate,"
query += "?ParcelId,"; + "?SnapshotId,"
query += "?ParentEstate,"; + "?SimName,"
query += "?SnapshotId,"; + "?GlobalPos,"
query += "?SimName,"; + "?ParcelName,"
query += "?GlobalPos,"; + "?Flags,"
query += "?ParcelName,"; + "?ListingPrice ) "
query += "?Flags,"; + "ON DUPLICATE KEY UPDATE "
query += "?ListingPrice ) "; + "category=?Category, "
query += "ON DUPLICATE KEY UPDATE "; + "expirationdate=?ExpirationDate, "
query += "category=?Category, "; + "name=?Name, "
query += "expirationdate=?ExpirationDate, "; + "description=?Description, "
query += "name=?Name, "; + "parentestate=?ParentEstate, "
query += "description=?Description, "; + "posglobal=?GlobalPos, "
query += "parentestate=?ParentEstate, "; + "parcelname=?ParcelName, "
query += "posglobal=?GlobalPos, "; + "classifiedflags=?Flags, "
query += "parcelname=?ParcelName, "; + "priceforlisting=?ListingPrice, "
query += "classifiedflags=?Flags, "; + "snapshotuuid=?SnapshotId"
query += "priceforlisting=?ListingPrice, "; ;
query += "snapshotuuid=?SnapshotId";
if(string.IsNullOrEmpty(ad.ParcelName)) if(string.IsNullOrEmpty(ad.ParcelName))
ad.ParcelName = "Unknown"; ad.ParcelName = "Unknown";
@ -245,10 +244,7 @@ namespace OpenSim.Data.MySQL
public bool DeleteClassifiedRecord(UUID recordId) public bool DeleteClassifiedRecord(UUID recordId)
{ {
string query = string.Empty; const string query = "DELETE FROM classifieds WHERE classifieduuid = ?recordId";
query += "DELETE FROM classifieds WHERE ";
query += "classifieduuid = ?recordId";
try try
{ {
@ -275,10 +271,8 @@ namespace OpenSim.Data.MySQL
public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result) public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
{ {
string query = string.Empty;
query += "SELECT * FROM classifieds WHERE "; const string query = "SELECT * FROM classifieds WHERE classifieduuid = ?AdId";
query += "classifieduuid = ?AdId";
try try
{ {
@ -326,10 +320,8 @@ namespace OpenSim.Data.MySQL
#region Picks Queries #region Picks Queries
public OSDArray GetAvatarPicks(UUID avatarId) public OSDArray GetAvatarPicks(UUID avatarId)
{ {
string query = string.Empty; const string query = "SELECT `pickuuid`,`name` FROM userpicks WHERE creatoruuid = ?Id";
query += "SELECT `pickuuid`,`name` FROM userpicks WHERE ";
query += "creatoruuid = ?Id";
OSDArray data = new OSDArray(); OSDArray data = new OSDArray();
try try
@ -369,12 +361,8 @@ namespace OpenSim.Data.MySQL
public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId) public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
{ {
string query = string.Empty;
UserProfilePick pick = new UserProfilePick(); UserProfilePick pick = new UserProfilePick();
const string query = "SELECT * FROM userpicks WHERE creatoruuid = ?CreatorId AND pickuuid = ?PickId";
query += "SELECT * FROM userpicks WHERE ";
query += "creatoruuid = ?CreatorId AND ";
query += "pickuuid = ?PickId";
try try
{ {
@ -427,33 +415,33 @@ namespace OpenSim.Data.MySQL
public bool UpdatePicksRecord(UserProfilePick pick) public bool UpdatePicksRecord(UserProfilePick pick)
{ {
string query = string.Empty; const string query =
"INSERT INTO userpicks VALUES ("
query += "INSERT INTO userpicks VALUES ("; + "?PickId,"
query += "?PickId,"; + "?CreatorId,"
query += "?CreatorId,"; + "?TopPick,"
query += "?TopPick,"; + "?ParcelId,"
query += "?ParcelId,"; + "?Name,"
query += "?Name,"; + "?Desc,"
query += "?Desc,"; + "?SnapshotId,"
query += "?SnapshotId,"; + "?User,"
query += "?User,"; + "?Original,"
query += "?Original,"; + "?SimName,"
query += "?SimName,"; + "?GlobalPos,"
query += "?GlobalPos,"; + "?SortOrder,"
query += "?SortOrder,"; + "?Enabled,"
query += "?Enabled,"; + "?Gatekeeper)"
query += "?Gatekeeper)"; + "ON DUPLICATE KEY UPDATE "
query += "ON DUPLICATE KEY UPDATE "; + "parceluuid=?ParcelId,"
query += "parceluuid=?ParcelId,"; + "name=?Name,"
query += "name=?Name,"; + "description=?Desc,"
query += "description=?Desc,"; + "user=?User,"
query += "user=?User,"; + "simname=?SimName,"
query += "simname=?SimName,"; + "snapshotuuid=?SnapshotId,"
query += "snapshotuuid=?SnapshotId,"; + "pickuuid=?PickId,"
query += "pickuuid=?PickId,"; + "posglobal=?GlobalPos,"
query += "posglobal=?GlobalPos,"; + "gatekeeper=?Gatekeeper"
query += "gatekeeper=?Gatekeeper"; ;
try try
{ {
@ -493,10 +481,7 @@ namespace OpenSim.Data.MySQL
public bool DeletePicksRecord(UUID pickId) public bool DeletePicksRecord(UUID pickId)
{ {
string query = string.Empty; string query = "DELETE FROM userpicks WHERE pickuuid = ?PickId";
query += "DELETE FROM userpicks WHERE ";
query += "pickuuid = ?PickId";
try try
{ {
@ -526,11 +511,7 @@ namespace OpenSim.Data.MySQL
#region Avatar Notes Queries #region Avatar Notes Queries
public bool GetAvatarNotes(ref UserProfileNotes notes) public bool GetAvatarNotes(ref UserProfileNotes notes)
{ // WIP { // WIP
string query = string.Empty; const string query = "SELECT `notes` FROM usernotes WHERE useruuid = ?Id AND targetuuid = ?TargetId";
query += "SELECT `notes` FROM usernotes WHERE ";
query += "useruuid = ?Id AND ";
query += "targetuuid = ?TargetId";
try try
{ {
@ -568,26 +549,25 @@ namespace OpenSim.Data.MySQL
public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result) public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
{ {
string query = string.Empty; string query;
bool remove; bool remove;
if(string.IsNullOrEmpty(note.Notes)) if(string.IsNullOrEmpty(note.Notes))
{ {
remove = true; remove = true;
query += "DELETE FROM usernotes WHERE "; query = "DELETE FROM usernotes WHERE useruuid=?UserId AND targetuuid=?TargetId";
query += "useruuid=?UserId AND ";
query += "targetuuid=?TargetId";
} }
else else
{ {
remove = false; remove = false;
query += "INSERT INTO usernotes VALUES ( "; query = "INSERT INTO usernotes VALUES ("
query += "?UserId,"; + "?UserId,"
query += "?TargetId,"; + "?TargetId,"
query += "?Notes )"; + "?Notes )"
query += "ON DUPLICATE KEY "; + "ON DUPLICATE KEY "
query += "UPDATE "; + "UPDATE "
query += "notes=?Notes"; + "notes=?Notes"
;
} }
try try
@ -621,10 +601,7 @@ namespace OpenSim.Data.MySQL
#region Avatar Properties #region Avatar Properties
public bool GetAvatarProperties(ref UserProfileProperties props, ref string result) public bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
{ {
string query = string.Empty; string query = "SELECT * FROM userprofile WHERE useruuid = ?Id";
query += "SELECT * FROM userprofile WHERE ";
query += "useruuid = ?Id";
try try
{ {
@ -673,35 +650,36 @@ namespace OpenSim.Data.MySQL
props.PublishProfile = false; props.PublishProfile = false;
props.PublishMature = false; props.PublishMature = false;
query = "INSERT INTO userprofile ("; query = "INSERT INTO userprofile ("
query += "useruuid, "; + "useruuid, "
query += "profilePartner, "; + "profilePartner, "
query += "profileAllowPublish, "; + "profileAllowPublish, "
query += "profileMaturePublish, "; + "profileMaturePublish, "
query += "profileURL, "; + "profileURL, "
query += "profileWantToMask, "; + "profileWantToMask, "
query += "profileWantToText, "; + "profileWantToText, "
query += "profileSkillsMask, "; + "profileSkillsMask, "
query += "profileSkillsText, "; + "profileSkillsText, "
query += "profileLanguages, "; + "profileLanguages, "
query += "profileImage, "; + "profileImage, "
query += "profileAboutText, "; + "profileAboutText, "
query += "profileFirstImage, "; + "profileFirstImage, "
query += "profileFirstText) VALUES ("; + "profileFirstText) VALUES ("
query += "?userId, "; + "?userId, "
query += "?profilePartner, "; + "?profilePartner, "
query += "?profileAllowPublish, "; + "?profileAllowPublish, "
query += "?profileMaturePublish, "; + "?profileMaturePublish, "
query += "?profileURL, "; + "?profileURL, "
query += "?profileWantToMask, "; + "?profileWantToMask, "
query += "?profileWantToText, "; + "?profileWantToText, "
query += "?profileSkillsMask, "; + "?profileSkillsMask, "
query += "?profileSkillsText, "; + "?profileSkillsText, "
query += "?profileLanguages, "; + "?profileLanguages, "
query += "?profileImage, "; + "?profileImage, "
query += "?profileAboutText, "; + "?profileAboutText, "
query += "?profileFirstImage, "; + "?profileFirstImage, "
query += "?profileFirstText)"; + "?profileFirstText)"
;
dbcon.Close(); dbcon.Close();
dbcon.Open(); dbcon.Open();
@ -743,15 +721,10 @@ namespace OpenSim.Data.MySQL
public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result) public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)
{ {
string query = string.Empty; const string query = "UPDATE userprofile SET profileURL=?profileURL,"
+ "profileImage=?image, profileAboutText=?abouttext,"
query += "UPDATE userprofile SET "; + "profileFirstImage=?firstlifeimage, profileFirstText=?firstlifetext "
query += "profileURL=?profileURL, "; + "WHERE useruuid=?uuid";
query += "profileImage=?image, ";
query += "profileAboutText=?abouttext,";
query += "profileFirstImage=?firstlifeimage,";
query += "profileFirstText=?firstlifetext ";
query += "WHERE useruuid=?uuid";
try try
{ {
@ -786,15 +759,13 @@ namespace OpenSim.Data.MySQL
#region Avatar Interests #region Avatar Interests
public bool UpdateAvatarInterests(UserProfileProperties up, ref string result) public bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
{ {
string query = string.Empty; const string query = "UPDATE userprofile SET "
+ "profileWantToMask=?WantMask, "
query += "UPDATE userprofile SET "; + "profileWantToText=?WantText,"
query += "profileWantToMask=?WantMask, "; + "profileSkillsMask=?SkillsMask,"
query += "profileWantToText=?WantText,"; + "profileSkillsText=?SkillsText, "
query += "profileSkillsMask=?SkillsMask,"; + "profileLanguages=?Languages "
query += "profileSkillsText=?SkillsText, "; + "WHERE useruuid=?uuid";
query += "profileLanguages=?Languages ";
query += "WHERE useruuid=?uuid";
try try
{ {
@ -828,18 +799,17 @@ namespace OpenSim.Data.MySQL
public OSDArray GetUserImageAssets(UUID avatarId) public OSDArray GetUserImageAssets(UUID avatarId)
{ {
OSDArray data = new OSDArray(); OSDArray data = new OSDArray();
string query = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id"; const string queryA = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id";
// Get classified image assets // Get classified image assets
try try
{ {
using (MySqlConnection dbcon = new MySqlConnection(ConnectionString)) using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
{ {
dbcon.Open(); dbcon.Open();
using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`classifieds`"), dbcon)) using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`classifieds`"), dbcon))
{ {
cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
@ -858,7 +828,7 @@ namespace OpenSim.Data.MySQL
dbcon.Close(); dbcon.Close();
dbcon.Open(); dbcon.Open();
using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon)) using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`userpicks`"), dbcon))
{ {
cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
@ -877,9 +847,9 @@ namespace OpenSim.Data.MySQL
dbcon.Close(); dbcon.Close();
dbcon.Open(); dbcon.Open();
query = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id"; const string queryB = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id";
using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon)) using (MySqlCommand cmd = new MySqlCommand(string.Format (queryB,"`userpicks`"), dbcon))
{ {
cmd.Parameters.AddWithValue("?Id", avatarId.ToString()); cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
@ -909,11 +879,7 @@ namespace OpenSim.Data.MySQL
#region User Preferences #region User Preferences
public bool GetUserPreferences(ref UserPreferences pref, ref string result) public bool GetUserPreferences(ref UserPreferences pref, ref string result)
{ {
string query = string.Empty; const string query = "SELECT imviaemail,visible,email FROM usersettings WHERE useruuid = ?Id";
query += "SELECT imviaemail,visible,email FROM ";
query += "usersettings WHERE ";
query += "useruuid = ?Id";
try try
{ {
@ -937,10 +903,9 @@ namespace OpenSim.Data.MySQL
dbcon.Close(); dbcon.Close();
dbcon.Open(); dbcon.Open();
query = "INSERT INTO usersettings VALUES "; const string queryB = "INSERT INTO usersettings VALUES (?uuid,'false','false', ?Email)";
query += "(?uuid,'false','false', ?Email)";
using (MySqlCommand put = new MySqlCommand(query, dbcon)) using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
{ {
put.Parameters.AddWithValue("?Email", pref.EMail); put.Parameters.AddWithValue("?Email", pref.EMail);
@ -966,13 +931,9 @@ namespace OpenSim.Data.MySQL
public bool UpdateUserPreferences(ref UserPreferences pref, ref string result) public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
{ {
string query = string.Empty; const string query = "UPDATE usersettings SET imviaemail=?ImViaEmail,"
+ "visible=?Visible, email=?EMail "
query += "UPDATE usersettings SET "; + "WHERE useruuid=?uuid";
query += "imviaemail=?ImViaEmail, ";
query += "visible=?Visible, ";
query += "email=?EMail ";
query += "WHERE useruuid=?uuid";
try try
{ {
@ -1005,11 +966,7 @@ namespace OpenSim.Data.MySQL
#region Integration #region Integration
public bool GetUserAppData(ref UserAppData props, ref string result) public bool GetUserAppData(ref UserAppData props, ref string result)
{ {
string query = string.Empty; const string query = "SELECT * FROM `userdata` WHERE UserId = ?Id AND TagId = ?TagId";
query += "SELECT * FROM `userdata` WHERE ";
query += "UserId = ?Id AND ";
query += "TagId = ?TagId";
try try
{ {
@ -1031,13 +988,8 @@ namespace OpenSim.Data.MySQL
} }
else else
{ {
query += "INSERT INTO userdata VALUES ( "; const string queryB = "INSERT INTO userdata VALUES (?UserId, ?TagId, ?DataKey, ?DataVal)";
query += "?UserId,"; using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
query += "?TagId,";
query += "?DataKey,";
query += "?DataVal) ";
using (MySqlCommand put = new MySqlCommand(query, dbcon))
{ {
put.Parameters.AddWithValue("?UserId", props.UserId.ToString()); put.Parameters.AddWithValue("?UserId", props.UserId.ToString());
put.Parameters.AddWithValue("?TagId", props.TagId.ToString()); put.Parameters.AddWithValue("?TagId", props.TagId.ToString());
@ -1064,14 +1016,7 @@ namespace OpenSim.Data.MySQL
public bool SetUserAppData(UserAppData props, ref string result) public bool SetUserAppData(UserAppData props, ref string result)
{ {
string query = string.Empty; const string query = "UPDATE userdata SET TagId = ?TagId, DataKey = ?DataKey, DataVal = ?DataVal WHERE UserId = ?UserId AND TagId = ?TagId";
query += "UPDATE userdata SET ";
query += "TagId = ?TagId, ";
query += "DataKey = ?DataKey, ";
query += "DataVal = ?DataVal WHERE ";
query += "UserId = ?UserId AND ";
query += "TagId = ?TagId";
try try
{ {