Skip to content

Commit

Permalink
Merge pull request #3572 from Ginger-Automation/BugFix/DatabaseIssues
Browse files Browse the repository at this point in the history
Changes for Database related Bug for Mongodb and Couchbase db
  • Loading branch information
aditydha committed Apr 5, 2024
2 parents 16922e2 + 254598f commit 6839511
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions Ginger/GingerCoreNET/Database/NoSqlBase/GingerCouchbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,35 @@ public bool ConnectToBucket(string bucketName)
private string GetBucketName(string inputSQL)
{
string bucketName = string.Empty;
string inputSQLLower = inputSQL.ToLower();
int bucket1 = 0;
int bucket2 = 0;
string[] bucketNameArray;
if (Action == ActDBValidation.eDBValidationType.RecordCount)
{
bucketName = inputSQL.Replace("`", "");
}else
bucketNameArray = bucketName.Split('.');
bucketName = bucketNameArray[0].Replace("'", "");
}
else
{
if (Action == ActDBValidation.eDBValidationType.UpdateDB){
bucket1 = inputSQLLower.IndexOf("`");
}else{
bucket1 = inputSQLLower.IndexOf(" from ") + 6;
if (Action == ActDBValidation.eDBValidationType.UpdateDB)
{
bucketName = inputSQL.Substring(inputSQL.ToLower().IndexOf("Update ") + 7);
}
else
{
bucketName = inputSQL.Substring(inputSQL.ToLower().IndexOf(" from ") + 6);
}
bucketNameArray = bucketName.Split('.');
bucketName = bucketNameArray[0].Trim();
int index = bucketName.IndexOf(" ");
if (index != -1)
{
bucketName = bucketName.Substring(0, index).Replace("`", "");
}
else
{
bucketName = bucketName.Substring(0, bucketName.Length - 1).Replace("`", "");
}
bucket2 = inputSQLLower.IndexOf("`", bucket1 + 1);
bucketName = inputSQL.Substring(bucket1, bucket2 - bucket1);

}
bucketName = bucketName.Replace("`", "");
bucketName = bucketName.Replace("'", "");
return bucketName;
}

Expand Down Expand Up @@ -204,9 +214,8 @@ public override void PerformDBAction()
}
break;
case Actions.ActDBValidation.eDBValidationType.RecordCount:
result = clusterCB.Query<dynamic>("Select Count(*) as RECORDCOUNT from `" + bucketName + "`");
var count = result.Rows[0];
Act.ParseJSONToOutputValues(count.ToString(), 1);
result = clusterCB.Query<dynamic>("Select Count(*) as RECORDCOUNT from " + SQLCalculated + "");
Act.ParseJSONToOutputValues(result.Rows[0].ToString(), 1);
break;
case Actions.ActDBValidation.eDBValidationType.UpdateDB:
result = clusterCB.Query<dynamic>(SQLCalculated);
Expand Down
2 changes: 1 addition & 1 deletion Ginger/GingerCoreNET/Database/NoSqlBase/GingerMongoDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public override void PerformDBAction()
else
{
var result = collection.Find(GetQueryParamater(SQLCalculated, "find")).
Project(GetQueryParamater(SQLCalculated, "project")).
//Project(GetQueryParamater(SQLCalculated, "project")). //Commented this to include _id colmun in output values
Sort(BsonDocument.Parse(GetQueryParamater(SQLCalculated, "sort"))).
Limit(Convert.ToInt32(GetQueryParamater(SQLCalculated, "limit"))).
ToList();
Expand Down

0 comments on commit 6839511

Please sign in to comment.