DbCommand , Must Declare a variable error - ado.net

This is my code. I have added the db parameter too but it still shows me error (on execution). Must declare a scalar variable
DbCommand command;
StringBuilder query = new StringBuilder(
#"SELECT isnull(UpsellService_OID,'') UpsellService_OID," + Environment.NewLine +
" isnull(ServiceName,'') ServiceName," + Environment.NewLine +
" isnull(ServiceDescription,'') ServiceDescription," + Environment.NewLine +
" isnull(Create_By,'') Create_By," + Environment.NewLine +
" isnull(Create_Date,'') Create_Date," + Environment.NewLine +
" isnull(Modify_By,'') Modify_By," + Environment.NewLine +
" isnull(Modify_Date,'') Modify_Date," + Environment.NewLine +
" isnull(Active_f,'') Active_f" + Environment.NewLine +
"FROM TRGPAYROLL.ZONG.UPSELLSERVICES " + Environment.NewLine +
"WHERE 1 = 1");
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
query.Append(" AND ServiceName like '%' #ServiceName '%'");
}
command = db.GetSqlStringCommand(query.ToString());
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
db.AddInParameter(command, "ServiceName", DbType.String, idObject.ServiceName);
}
return command;

I would rewrite the last part of your code in this way
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
query.Append(" AND ServiceName like #ServiceName");
}
command = db.GetSqlStringCommand(query.ToString());
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
db.AddInParameter(command, "#ServiceName", DbType.String, "%" + idObject.ServiceName + "%");
}
The wildcard are added directly to the value of the parameter, while the placeholder of the parameter should be free from any string concatenations. However there are many details missing to be sure of the correctness of this answer. In particular Ican only assume the inner workings of the methods GetSqlStringCommand and AddInParameter

#ServiceName variable is not declared in your SQL statement. Append to beggining of it something like
DECLARE #ServiceName AS nchar(32)
SET #ServiceName = ....

Related

How to loop through an array of strings Gatling during scenario building

I'm trying to loop through an array of products (Strings) in order to execute a call for each of them but I'm mismatching some types during scenario building, here is an example of what I'm trying to do:
val createAddToCart: ScenarioBuilder = scenario("Add to cart").exec(CartRequest.addToCart())
This is my CartRequest object:
def addToCart(): Unit (???) = {
for (product <- products) {
addToCart(product)
}
}
def addToCart(productId:String): ChainBuilder =
{
exec(http("addToCart")
.post(addToCartUrl)
.headers(authHeaders)
.body(generateRequestBodyForProduct(productId)).asJson
.check(bodyString.saveAs("body"))
).exec(
session => {
body = session("body").as[String]
println("response body " + body)
session
}
)
}
def generateRequestBodyForProduct(productId: String): Body with (Expression[String]) =
{
StringBody("{ \"productId\": \"" + productId + "\"," +
" \"qty\": " + 1 + " , " +
"\"storeId\": \"" + storeId + "\"}")
}
Obviously, I'm having problems calling CartRequest.addToCart() due to type mismatching (Unit to ChainBuilder).
Is there a way to execute and return the addToCart method as a list of scenarios?
I hope I explained myself well.
Thanks for your time.
First, you don't look like a Scala developper. You should probably use the new Java DSL available since Gatling 3.7.
Then, you're not using the Gatling constructs properly.
your for loop should be a Gatling foreach instead
the dynamic productId in your request body should be resolved with Gatling Expression Language => "{ \"productId\": \"#{productId}\", \"qty\": " + 1 + " , " + "\"storeId\": \"" + storeId + "\"}"

JPQL. JPA Query. How to get size of named parameter collection

I'm trying to define custom method in repository interface
public interface RequestRepository extends JpaRepository<Request, Long> {
#Query("SELECT r FROM Request r " +
"LEFT JOIN FETCH r.pathParams pp " +
"WHERE r.responseCode = :code " +
"AND r.requestMethod = :method " +
"AND r.requestPath = :path " +
"AND r.requestBody = :body " +
"AND r.apiDetails = :apidetails " +
"AND (pp IN :pathparams OR r.pathParams IS EMPTY) " +
"AND SIZE(r.pathParams) = :pathparamssize "
)
Optional<Request> findByDetails(
#Param("code") String code,
#Param("method") RequestMethod method,
#Param("path") String path,
#Param("body") RequestBody body,
#Param("apidetails") ApiDetails apidetails,
#Param("pathparams") Set<PathParam> pathparams,
#Param("pathparamssize") Integer pathparamssize
);
}
It works, but I believe it can be done in better way
As you can see I declared redundant parameter "pathparamssize" (IMO)
I tried to do that like "AND SIZE(r.pathParams) = SIZE(:pathparams) " but it doesn't want to work with "SIZE(:pathparams)"
can you please advise something?
many thanks in advance

Scheduler Date Range MVVM

My question is very simple:
How do I get the current date range of the Kendo Scheduler?
I have checked out the example that's in the API Reference, but that one doesn't work for me.
Code:
function getCurrentDateRange(){
try{
var view = this.view();
console.log(view);
return "?startdate=" + kendo.toString(view.startDate(), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(view.endDate(), "yyyy-MM-dd");
}
catch(error){ console.log("Scheduler: Could not get schedulers daterange \n Error: " + error)}
//Default value
return "?startdate=" + kendo.toString(new Date().addDays(-30), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(new Date().addDays(30), "yyyy-MM-dd");
}
The solution for me was to reference the scheduler directly.
try{
var view = $("#schedulerViewScheduler").data("kendoScheduler").view();
console.log(view);
return "&startdate=" + kendo.toString(view.startDate(), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(view.endDate(), "yyyy-MM-dd");
}
catch(error){ console.log("Scheduler: Could not get schedulers daterange \n Error: " + error)}
return "&startdate=" + kendo.toString(new Date().addDays(-30), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(new Date().addDays(30), "yyyy-MM-dd");

How to create a derby user

I tried to set the DB schema name by schema.xml but it caused a schema name duplication in the generated SQL statement for ID generators. (Duplicate schema name in sequece generation)
I read the schema is defined by the passed user at connection time. Now I would like to set the schema by this way.
But I don't know how can I create a new Derby user and link it with the desired schema. Can somebody help me?
Environment: NetBeans, Glassfish, Derby
I have found this:
CALL SYSCS_UTIL.SYSCS_CREATE_USER('username', 'password')
But Derby answers:
Error code -1, SQL state 42Y03: 'SYSCS_UTIL.SYSCS_CREATE_USER' is not recognized as a function or procedure.
Why? I have connected to the db as the default admin user.
Or if I try to dispatch this command from a GUI tool, Derby says:
[Error Code: 0, SQL State: 42Y07] : Schema 'SYSCS_UTIL' does not exist
To Create user in Derby :
I am using Command Line Interface and I have already set my System environment variable to Derby.
Otherwise you can write these command into your CLI
java -jar %DERBY_HOME%\lib\derbyrun.jar ij
and hit Enter key to run ij tool, and you will see a prompt like this:
ij>
Now type the following command to create a user (replace sam by the desired username and sampass by the desired password):
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user.sam','sampass');
Now hit enter. This should give a message like this:
0 rows inserted/updated/deleted.
here is a solution (heavily commented):
String setProperty = "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(";
String getProperty = "VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY(";
String requireAuth = "'derby.connection.requireAuthentication'";
String sqlAuthorization = "'derby.database.sqlAuthorization'";
String defaultConnMode = "'derby.database.defaultConnectionMode'";
String fullAccessUsers = "'derby.database.fullAccessUsers'";
String readOnlyAccessUsers = "'derby.database.readOnlyAccessUsers'";
String provider = "'derby.authentication.provider'";
String propertiesOnly = "'derby.database.propertiesOnly'";
System.out.println("Turning on authentication and SQL authorization.");
Statement s = conn.createStatement();
// Set requireAuthentication
s.executeUpdate(setProperty + requireAuth + ", 'true')");
//CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.connection.requireAuthentication','true'
// Set sqlAuthorization
s.executeUpdate(setProperty + sqlAuthorization + ", 'true')");
//CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.sqlAuthentication','true'
// Retrieve and display property values
ResultSet rs = s.executeQuery(getProperty + requireAuth + ")");
rs.next();
System.out.println("Value of requireAuthentication is " + rs.getString(1));
rs = s.executeQuery(getProperty + sqlAuthorization + ")");
rs.next();
System.out.println("Value of sqlAuthorization is " + rs.getString(1));
// Set authentication scheme to Derby builtin
s.executeUpdate(setProperty + provider + ", 'BUILTIN')");
// Create some sample users
s.executeUpdate(setProperty + "'derby.user." + txtUname.getText() + "', '" + txtPw1.getText() + "')" );
// Define noAccess as default connection mode
s.executeUpdate(setProperty + defaultConnMode + ", 'noAccess')");
// Confirm default connection mode
rs = s.executeQuery(getProperty + defaultConnMode + ")");
rs.next();
System.out.println("Value of defaultConnectionMode is " + rs.getString(1));
// Define read-write users
s.executeUpdate(setProperty + fullAccessUsers + ", '" + txtUname.getText() + "')");
// Define read-only user
// s.executeUpdate(setProperty + readOnlyAccessUsers + ", 'guest')");
// Confirm full-access users
rs = s.executeQuery(getProperty + fullAccessUsers + ")");
rs.next();
System.out.println("Value of fullAccessUsers is " + rs.getString(1));
// Confirm read-only users
rs = s.executeQuery(getProperty + readOnlyAccessUsers + ")");
rs.next();
System.out.println("Value of readOnlyAccessUsers is " + rs.getString(1));
// We would set the following property to TRUE only when we were
// ready to deploy. Setting it to FALSE means that we can always
// override using system properties if we accidentally paint
// ourselves into a corner.
s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" + "'derby.database.propertiesOnly', 'false')");
s.close();
Let me know if that works (or not) for you.

Does systeminfo command work for WIndows 2003?

Is there a common command which can give the system information for windows2003 and above versions?
I have used it many times with windows xp,2003,vista its works fine
You also can script "system information acquisition" through WMI calls.
Use the WMIC Code Creator and a little VB script, and you can obtain precisely the informations you want/need, as opposed to the static systeminfo command.
For instance:
public string GetHardDisks() {
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_LogicalDisk");
StringBuilder sb = new StringBuilder();
foreach (ManagementObject wmi in searcher.Get()) {
try {
sb.Append("Drive Device ID: " +
wmi.GetPropertyValue("DeviceID").ToString() +Environment.NewLine);
sb.Append("Caption: " + wmi.GetPropertyValue("Caption").ToString() + Environment.NewLine);
sb.Append("Volume Serial Number: " + wmi.GetPropertyValue("VolumeSerialNumber").ToString()
+ Environment.NewLine);
sb.Append("Free Space: " + wmi.GetPropertyValue("FreeSpace").ToString() + "
bytes free" + Environment.NewLine + Environment.NewLine);
}
catch {
return sb.ToString();
}
}
return sb.ToString();
}