I'm trying to write a simple 'IF' statement on MariaDb but I stumbled on the basics.
This is my code:
SELECT #variable := `value` FROM configuration WHERE key = 'key'
this seems to work, but can a variable declared in this way be used in a if ?
IF #variable = "foo" THEN
UPDATE ...
UPDATE ...
DELETE ...
ELSE
UPDATE ...
END IF;
I'm forced to put this code only in a procedure ? Most of the code I read put all this inside a procedure but in the official documentation here there is nothing about it.
When I try to run this script inside phpMyAdmin I get:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF #variable = "foo" THEN
UPDATE tags SET ....
The if statement can be used outside of stored procedures.
PHPMyAdmin apprently has a delimiter as part of its UI.
The alternative is:
UPDATE ... WHERE #variable = "foo"
UPDATE ... WHERE #variable = "foo"
DELETE ... WHERE #variable = "foo"
UPDATE ... WHERE #variable != "foo"
Related
I'm trying to apply regex in something like this, in terraform.
variable "version" {
type = "string"
default = https://s3-us-east-1.amazonaws.com/bucket/folder/item-v1.2/item-item2-v1.2.gz
description = "version"
}
name = "${replace(var.version, "//", "")}"
I just need to replace everything and output only "v1.2" for the name, specifically from the item-v1.2 file path. I was thinking of doing something along the lines of
name = "${replace(var.version, "//", "")}"
wherein I replace everything but v1.2.
Any idea how to do it? Thank you in advance!
There are a couple of issues with your variable definition (e.g. wrong use of quotes, variable name "version" is reserved due to its special meaning inside module blocks, and so on) so I operate on the following:
variable "my_version" {
type = string
default = "https://s3-us-east-1.amazonaws.com/bucket/folder/item-v1.2/item-item2-v1.2.gz"
description = "version"
}
Then you can extract the version (or replace everything else except the version as requested) from the sub-folder path like this (this has been run and tested with terraform console):
$ terraform console
> var.my_version
"https://s3-us-east-1.amazonaws.com/bucket/folder/item-v1.2/item-item2-v1.2.gz"
> regex(".*-(.*)/.*.gz", var.my_version)[0]
"v1.2"
> replace(var.my_version, "/.*-(.*)/.*.gz/", "<before> $1 <after>")
"<before> v1.2 <after>"
I'm new to declarative pipeline and exploring its features. I tried to use regex. The following example is the result of trial and error. Is there a nicer solution out there? I'm looking for a new shiny declarative pipeline way, if there is any.
What I do not get is, why do I have to use the script{}-Enviroment and why do I have to use a local variable (def matcherX)?
working example followed by first attemts:
Working Example:
pipeline {
environment {
dummyText = 'aaa123aaa'
transfare = ''
}
agent any
stages {
stage('regex') {
steps{
script{
def matcherX = dummyText =~ /(\d+)/
transfare = matcherX[0][0]
echo transfare // results in 123
}
}
}
}
}
Error: without a script{}
/*
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 11: Expected a step # line 11, column 21.
def matcherX = dummyText =~ /(\d+)/
^
WorkflowScript: 12: Expected a step # line 12, column 21.
transfare = matcherX[0][0]
*/
Error: with script but with a global variable
//script{
// transfare = dummyText =~ /(\d+)/
/*
// No line displayed where error occured???
an exception which occurred:
in field org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptScript.script
in object org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript#192ebed
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2#31fd6bc8
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2#609aa9b5
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#3e51c1c3
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#3e51c1c3
Caused: java.io.NotSerializableException: java.util.regex.Matcher
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
*/
The script block indicates departure from the pure declarative syntax. Ideally builds (just as any other process) could take advantage of a pure declarative syntax to avoid implicit dependencies between steps.
The global variable of a matcher type fails to serialize which is needed to pass it between the Jenkins master and the slave (I guess).
I want to use If-Condition with multiple actions in Robot Framework
${x} Set Variable 5
Run Keyword If ${x} == 5
... ${Test1} = Set Variable MyName
... ${Test2} = Set Variable MyLastName
... Else
... ${Test1} = Set Variable MyAddress
... ${Test2} = Set Variable MyTelephone
But it is not working
Error show FAIL : Variable '${Test1}' not found.
Could you please tell me about using IF-Condition with multiple actions
You can use "Run Keywords" keyword to perform multiple actions in IF condition
Kindly go through below link:
IF ELSE in robot framework with variables assignment
You have to either cover both actions with one custom keyword and then call Run Keyword If or call the keyword Set Variable If twice or write such logic into python (jython...) library.
Please notice "And" while using "Run Keywords"; also ensure tab used.
Run Keyword If <condition1> <action1>
... ELSE IF <condition1>
... Run Keywords
... <action1>
... AND <action2>
Set Test Variable ${temp} rxu
Run Keyword if '${temp}'=='rxu'
... Run Keywords
... Log To Console this is one
... AND Log To Console This is two
... ELSE Run Keyword Log To Console another block
Refer following keyword :
Run Keyword If ${x} == 5 Set Variable MyName
Run Keyword If ${x} == 1 Set Variable LastName
Or
Run Keyword If ${x} == 5 Set Variable MyName
... ELSE IF ${x} == 2 Set Variable MyName
... ELSE IF ${x} == 3 Set Variable Middle Name
I have just setup my first installation of OTRS and I was setting up my first filtering when I found a 'possible' bug:
When the regex matches a zero (as in '0') and I try to assign it to a DynamicField (type text) using '[***]' I get an empty value (maybe it believes it's NULL??)
The actual regex works:
Node users: (.*?)\,
And what I'm parsing on the body:If I have a '1' it works fine
"...3.250. Node users: 1, Backend use..."
log:
Filter: 'variable name 4' Set param 'X-OTRS-DynamicField-variable4' to '1'
If I have a '0' OTRS doesn't see a value
"...3.250. Node users: 0, Backend use..."
log:
Filter: 'variable name 4' Set param 'X-OTRS-DynamicField-variable4' to ''
Any ideas? I'm no perl expert, but it looks like it's both successfully matching and unsuccessfully inserting in DB.
Without seeing some code, I'm left with guessing. My guess would be there's some logic:
if ( $variable ) { # do something };
Which means when the variable is present, but 0 it's evaluating as false when it shouldn't be. This can be easily fixed by tracking down the offending line and changing it to:
if ( defined $variable ) { #do something };
...specifically, the fn_listextendedproperty system function in MSSQL 2005.
I have added an Extended Property to my database object, named 'schemaVersion'. In my MSVC application, using ADO, I need to determine if that Extended Property exists and, if it does, return the string value out of it.
Here is the T-SQL code that does what I want. How do I write this in C++/ADO, or otherwise get the job done?
select value as schemaVer
from fn_listextendedproperty(default, default, default, default, default, default, default)
where name=N'schemaVersion'
Here's the code I tried at first. It failed with the error listed below the code:
_CommandPtr cmd;
cmd.CreateInstance(__uuidof(Command));
cmd->ActiveConnection = cnn;
cmd->PutCommandText("select value "
"from fn_listextendedproperty(default, default, default, default, default, default, default) "
"where name=N'schemaVersion'");
VARIANT varCount;
cmd->Execute(NULL, NULL, adCmdText);
...here are the errors I peeled out of the ADO errors collection. The output is from my little utility function which adds the extra text like the thread ID etc, so ignore that.
(Proc:0x1930, Thread:0x8A0) INFO : === 1 Provider Error Messages : =======================
(Proc:0x1930, Thread:0x8A0) INFO : [ 1] (-2147217900) 'Incorrect syntax near the keyword 'default'.'
(Proc:0x1930, Thread:0x8A0) INFO : (SQLState = '42000')
(Proc:0x1930, Thread:0x8A0) INFO : (Source = 'Microsoft OLE DB Provider for SQL Server')
(Proc:0x1930, Thread:0x8A0) INFO : (NativeError = 156)
(Proc:0x1930, Thread:0x8A0) INFO : ==========================================================
EDIT: Updated the call according to suggestions. Also changed "SELECT value AS schemaVer" to just "SELECT value".
EDIT: Changed the first parameter of Execute() to NULL per suggestion. This fixed my original problem, and I proceeded to the next. :)
Try specifying NULL rather than default for each parameter of fn_listextendedproperty. This should hopefully then execute without errors, just leaving you to retrieve the result as your next step.
I still have not figured out how to do this directly. To get on with my life, I wrote a stored procedure which called the function:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[mh_getSchemaVersion]
#schemaVer VARCHAR(256) OUTPUT
AS
select #schemaVer = CAST( (select value from fn_listextendedproperty(default, default, default, default, default, default, default) where name=N'schemaVersion') AS varchar(256) )
return ##ROWCOUNT
...and then called thst sproc from my ADO/C++ code:
_CommandPtr cmd;
cmd.CreateInstance(__uuidof(Command));
cmd->ActiveConnection = cnn;
cmd->PutCommandText("mh_getSchemaVersion")_l
_variant_t schemaVar;
_ParameterPtr schemaVarParam = cmd->CreateParameter("#schemaVer", adVarChar, adParamOutput, 256);
cmd->GetParameters()->Append((IDispatch*)schemaVarParam);
cmd->Execute(NULL, NULL, adCmdStoredProc);
std::string v = (const char*)(_bstr_t)schemaVarParam->GetValue();
ver->hasVersion_ = true;
...which works, but I didn't want to have to deploy a new stored procedure.
So if anyone can come up with a solution to the original problem and show me how to call the system function directly from ADO/C++, I will accept that as the answer. Otherwise I'll just accept this.