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