appending static variable within sql query - append

I am trying to use the late static binding concept during insertion but I am getting a syntax error when I am writing this statement:
I am using php version 5.3.8
$resultArray = $this->connection->query("insert into " static::$table "(title,link) values('hi','hello')");

Looks like you forgot some dots to concatenate static::$table with the rest of the query string. Try this:
$resultArray = $this->connection->query("insert into " . static::$table . "(title,link) values('hi','hello')");

Related

How to cut a string from the end in UIPATH

I have this string: "C:\Procesos\rrhh\CorteDocumentos\Cortados\10001662-1_20060301_29_1_20190301.pdf" and im trying to get this part : "20190301". The problem is the lenght is not always the same. It would be:
"9001662-1_20060301_4_1_20190301".
I've tried this: item.ToString.Substring(66,8), but it doesn't work sometimes.
What can I do?.
This is a code example of what I said in my comment.
Sub Main()
Dim strFileName As String = ""
Dim di As New DirectoryInfo("C:\Users\Maniac\Desktop\test")
Dim aryFi As FileInfo() = di.GetFiles("*.pdf")
Dim fi As FileInfo
For Each fi In aryFi
Dim arrname() As String
arrname = Split(Path.GetFileNameWithoutExtension(fi.Name), "_")
strFileName = arrname(arrname.Count - 1)
Console.WriteLine(strFileName)
Next
End Sub
You could achieve this using a simple regular expressions, which has the added benefit of including pattern validation.
If you need to get exactly eight numbers from the end of file name (and after an underscore), you can use this pattern:
_(\d{8})\.pdf
And then this VB.NET line:
Regex.Match(fileName, "_(\d{8})\.pdf").Groups(1).Value
It's important to mention that Regex is by default case sensitive, so to prevent from being in a situations where "pdf" is matched and "PDF" is not, the patter can be adjusted like this:
(?i)_(\d{8})\.pdf
You can than use it directly in any expression window:
PS: You should also ensure that System.Text.RegularExpressions reference is in the Imports:
You can achieve it by this way as well :)
Path.GetFileNameWithoutExtension(Str1).Split("_"c).Last
Path.GetFileNameWithoutExtension
Returns the file name of the specified path string without the extension.
so with your String it will return to you - 10001662-1_20060301_29_1_20190301
then Split above String i.e. 10001662-1_20060301_29_1_20190301 based on _ and will return an array of string.
Last
It will return you the last element of an array returned by Split..
Regards..!!
AKsh

Angular2 Like request MongoDB

I want to do a pretty simple thing, a function that does a query to mongoDB using a Like. But I don't seem to make it works.
At the moment it looks like this :
searchChannel(valueToSearch:string){
this.items = Channels.find({'title':'/' + valueToSearch + '/'});
}
I tried /valueToSearch/ too, but it doesn't return any result.
To construct a regular expression from string you can use RegExp
searchChannel(valueToSearch:string){
this.items = Channels.find({'title': new RegExp(valueToSearch)});
}
Ok so... the issue is likely because you're inserting / characters into your mongo query. I think you want something like this:
searchChannel(valueToSearch:string){
this.items = Channels.find({'title': valueToSearch });
}
Unless the / characters are part of your stored content, they shouldn't be added to your search string.

adding params to joomla plugin based on external file

I am trying to develope a simple joomla plugin and i have a question, if you kindly could help me.
I have a long list of constants to use in my plugin, a group is to use with a joomla version and another group to use with another version, like this
//joomla version 2.5
$a01 = " some value "
$a02 = " some value "
$a03 =" some value "
....
....
$a99 = " some value "
//joomla version 3.0
$b01 = " some value "
$b02 = " some value "
$b03 = " some value "
....
....
$b99 = " some value "
In my plugin file i have this code:
if (!version_compare(JVERSION, '3.0', 'ge'))
{
// do something using constants for version less than 3.0
} else {
// do something using constants for version more than 3.0
}
For a better reading and organization where can hold those constants? In same file or in another file like (params or constants)? Which is the best approach? And how could i implement it?
What about placing it in a db-table? You retrieve them in your plugin by:
$db=JFactory::getDbo();
$db->setQuery('select key, value from #__yourtable where version ='.$version);
$list=$db-loadAssocList();
foreach($list as $v){
eval("define({$v['key']}, {$v['value']});");
}
Now all your constants for version $version are loaded.
...and if you want to be able to manage your constants from the joomla backend interface you could use a component-creator to quickly create this simple table with a full editing interface ( try component-creator.com )
regards Jonas (not affiliated with component-creator.com :) )

Passing dynamic value gets failed in Mongodb using java script

I have to copy the data from one collection to another collection based on a date. Here date is calculated as yesterday date dynamically and working properly.
If i pass the dynamic date value as /$yesterday/ to mongo find method, Its getting failed.
Assume data_timestamp format is 2013-08-20 17:04:40.633 and trying to get the result by like query.
Sample JS Code:
db=db.getSiblingDB('masterdb')
$today = new Date();
$yesterday = new Date($today);
$yesterday.setDate($today.getDate() - 1);
var $dd = $yesterday.getDate();
var $mm = $yesterday.getMonth()+1;
var $yyyy = $yesterday.getFullYear();
if($dd<10){$dd='0'+dd} if($mm<10){$mm='0'+$mm} $yesterday = $yyyy+'-'+$mm+'-'+$dd;
db.mastercollection.find( { "data_timestamp": /$yesterday/ } ).forEach( function(x){db.newcollection.insert(x)} );
Is any other way to pass dynamic value without using '$' symbol?
Please share your valuable comments
Thanks in advance...
Ramesh Kasi
The way you're doing your query now, I'm pretty sure that /$yesterday/ is being interpreted as a regular expression matching strings starting with "yesterday". A better approach would be to use the $regex operator so that you can pass in a javascript variable that holds the regular expression you hope to match.

Slow Cypher neo4j results when using REST GraphDb

I am working with the neo4j-rest-graphdb an just tried to use Cypher for fetching a simple Node result.
CypherParser parser = new CypherParser();
ExecutionEngine engine = new ExecutionEngine(graphDbService);
Query query = parser.parse( "START referenceNode = node (0) " +
"MATCH referenceNode-[PRODUCTS_REFERENCE]->products-[PRODUCT]->product " +
"RETURN product.productName " +
"ORDER BY product.productId " +
"SKIP 20"
"LIMIT 10");
ExecutionResult result = engine.execute( query );
Iterator<Map<String, Object>> iterator = result.javaIterator();
What is the best practise to iterate through the result? The last line causes my service to hang for ~6 sec. Without the iterator at the end the application is quiet fast. I also tried the webadmin cypher terminal, the results are fetched within 50ms. Am i doing something wrong?
In your case all the cypher operations (graph-matching, filtering etc. would go over the wire which is awfully chatty and slow) you don't want that !
The neo4j-rest-graphdb supports remote execution of cypher out of the box:
Just do, something like shown in this testcase:
RestCypherQueryEngine queryEngine = new RestCypherQueryEngine(restGraphDatabase.getRestAPI());
final String queryString = "start n=node({reference}) return n";
Map params = MapUtil.map("reference",0);
final Node result = (Node) queryEngine.query(queryString, params).to(Node.class).single();
assertEquals(restGraphDatabase.getReferenceNode(), result);
If I understood you correctly, graphDbService is a REST graph database, correct?
If you want to use Cypher on the Server, you should instead use the CypherPlugin. Look here: http://docs.neo4j.org/chunked/snapshot/cypher-plugin.html
I hope this helps,
Andrés