How do you concatenate two variables for the text of a select.genericlist - list

in this select.generic list I am wanting to concatenate two variables/fields for the "text" of this list. It is a functioning list.
<?php echo JHtml::_('select.genericlist', $this->assets, 'id', 'class="inputbox" onchange="document.location.href = this.value"', 'link', 'serialnumber' , $this->asset->link);?>
Where 'serialnumber' is the field used for the text of the list, I am trying to get 'model' AND 'serialnumber' so that it displays "Model: serialnumber" in the select list.
Everything i have found for concatenation does not work, and seems to just make a string 'model:serialnumber' which is a non-existant field.
using $model . $serialnumber is a no go as well, though using just one variable works fine.
Thanks for the help!

Simplest thing would be you do a concat at the db level.
So when generating $this->assets you put something like this in the query:
SELECT bla1, bla2, CONCAT('Model: ', bla3) AS text ...
or
SELECT bla1, bla2, CONCAT(model, ': ', serialnumber) AS text ...
if model is a db field.

Taking what Mike said I found where I needed to make the change to the query in the category model of my component. I wasted a lot of time thinking it had to be in the asset model:
$query->select($this->getState('list.select', 'a.id, a.name, CONCAT(a.model,\': \', a.serialnumber)AS modelserialnumber, ...
$query->from('`#__asset_details` AS a');
Thanks Mike for your help!

Related

influxdb query: specify or filter tag by regex

According to the docs, we can...
Use a regular expression to specify a tag with a value in the WHERE clause.
When I query my influxdb like this, I get the desired results.
> SELECT "field" FROM "measurement" WHERE tag = 19 😀
When replacing the where filtering by a regex, however, I get no results.
> SELECT "field" FROM "measurement" WHERE tag =~ /19/ 😕
Can someone tell me why that is?
Found the mistake myself...
I had both a field and a tag with the same key. So I was doing
> SELECT "filed_key" from "measurement" WHERE field_key =~ /val/
Now I have changed my schema so that keys across fields and tags are unique, and everything works as expected.
There's also a discussion about this phenomenon on github.
Regex using Flux Query for InfluxDB 2.0.
src: https://docs.influxdata.com/influxdb/cloud/query-data/flux/regular-expressions/
The following example excludes records that do not have _percent in a field key.
from(bucket: "example-bucket")
|> range(start: -15m)
|> filter(fn:(r) =>
r._measurement == "mem" and
r._field =~ /_percent/ )

Django - MyThing.objects.filter(name=None) vs MyThing.objects.filter(name__isnull=True) - which is better?

I have a table and want to find all rows where the name column is None.
Should I do:
MyThing.objects.filter(name=None)
or
MyThing.objects.filter(name__isnull=True)
What difference does it make?
According to the docs for exact and isnull, these produce the same SQL. Which you use is more of a stylistic choice than a performance or correctness one.
A quick check in the console outputted something like the following for me:
str(MyThing.objects.only('name').filter(name=None).query)
# 'SELECT `myapp_mything`.`id`, `myapp_mything`.`name` FROM `myapp_mything` WHERE `myapp_mything`.`name` IS NULL ORDER BY `myapp_mything`.`name` ASC'
str(MyThing.objects.only('name').filter(name__isnull=True).query)
# 'SELECT `myapp_mything`.`id`, `myapp_mything`.`name` FROM `myapp_mything` WHERE `myapp_mything`.`name` IS NULL ORDER BY `myapp_mything`.`name` ASC'
So they appear to be the same.

Matching number sequences in SQLite with random character separators

I have an sqlite database which has number sequences with random separators. For example
_id data
0 123-45/678>90
1 11*11-22-333
2 4-4-5-67891
I want to be able to query the database "intelligently" with and without the separators. For example, both these queries returning _id=0
SELECT _id FROM myTable WHERE data LIKE '%123-45%'
SELECT _id FROM myTable WHERE data LIKE '%12345%'
The 1st query works as is, but the 2nd query is the problem. Because the separators appear randomly in the database there are too many combinations to loop through in the search term.
I could create two columns, one with separators and one without, running each query against each column, but the database is huge so I want to avoid this if possible.
Is there some way to structure the 2nd query to achieve this as is ? Something like a regex on each row during the query ? Pseudo code
SELECT _id
FROM myTable
WHERE REPLACEALL(data,'(?<=\\d)[-/>*](?=\\d)','') LIKE '%12345%'
Ok this is far from being nice, but you could straightforwardly nest the REPLACE function. Example:
SELECT _id FROM myTable
WHERE REPLACE(..... REPLACE(REPLACE(data,'-',''),'_',''), .... '<all other separators>','') = '12345'
When using this in practice (--not that I would recommend it, but at least its simple), you surely might wrap it inside a function.
EDIT: for a small doc on the REPLACE function, see here, for example.
If I get it right, is this what you want?
SELECT _id
FROM myTable
WHERE Replace(Replace(Replace(data, '?', ''), '/', ''), '-', '') LIKE '%12345%'

How to read columns with spaces from coldfusion queries?

I am reading data from a spreadsheet. One of the column in the spreadsheet contains spaces.
For Example, Columns names are [first name,last name,roll].
I am getting a qryObj after reading the spreadsheet.
Now when i am trying to read first name from the query
<cfquery dbtype="query" name="getName">
SELECT [first name]
FROM qryObj
</cfquery>
It is throwing db error. I have tried with ['first name'] also but still it is throwing error.
The error is:
Query Of Queries syntax error.
Encountered "[. Incorrect Select List, Incorrect select column
I did crazy stuff like googling to see what people had done in other situations, and tried various SQL approaches to escaping non-standard column names (back ticks, square barackets, double quotes, combos thereof) , and drew a blank. So I agree with #da_didi that QoQ/IMQ does not cater for this. You should raise a ticket in the Adobe bug tracker.
You could do SELECT *, which removes the need to reference the column name. Or you could serialize the query, use a string replace to rename the column, deserialise it again then QoQ on the revised name. I'd only do this with a small amount of data though.
Or you could push back on the owbner of the XLS file and say "no can do unless you revise your column names".
You could also perhaps suppress the column names as they stand from the XLS file using excludeHeaderRow,and then specify your own columns names. How did I find out one could do that? By RTFMing the <cfspreadsheet> docs.
Thats easy:
Query
Select [FIRST NAME]
in output loop of query
["FIRST NAME"]
Try this - set a variable works for me
<cfset first_name = #spreadsheetData['first name'][CurrentRow]#>
You cannot. Best practices: I always replace all spaces with an underline.
Simple. Just alias the select. Select [FIRST NAME] as FIRSTNAME from qryObj

Extracting id number from a varchar in PostgreSQL

I have a field that contains mixed data with an id number that I want extract to another column. The column I wish to extract from has some records that match the format 'lastname, firstname-ID'. I only want to strip the 'ID' part, and from those columns who have a '-' and numbers following it.
So what I was trying to do was...
update data.xml_customerqueryrs
set new_id = regexp_replace(name, '[a-z]A-Z]', '')
where name like '%-%';
I know there is something minor that I need to fix, but I am not sure as the postgresql documentation for pattern matching doesn't really do a good job covering searching for only numerics.
If you actually only want to strip the 'ID' part:
new_id = regexp_replace(name, '-.*?$', '')
Or, if you, in fact, want to extract the ID part:
new_id = substring(name, '-(.*?)$')
I use the *? quantifier, so that only the last part is extracted, where a name has a - in it. Like:
Skeet-Gravell,John-1234
String functions in current manual
Or you can also do:
new_id = substr(name, strpos(name, '-'), length(name))
Ref: Strings