How can I change the name of the query result tabs in Navicat? - navicat

I'm running multiple queries at once and was wondering if I can assign different names to each of the tabs, so that the names are more useful than "Result 1", "Result 2", etc.

You can name the results tab by adding a special comment just before each query. The comment should be in the following format:
-- NAME: your-tab-name
Where your-tab-name can be anything you want. Here's an example:
-- NAME: premium users
select * from users where premium = 1;
-- NAME: others
select * from users where premium = 0;
Now instead of the tabs being named "Result 1" and "Result 2", they will be named "premium users" and "others".
You can also use the block comment syntax instead:
/* NAME: premium users */
select * from users where premium = 1;
/* NAME: others */
select * from users where premium = 0;
Here's an example of what named tabs would look like:

Related

CKEDitor: show / hide items by menu group

I have a context menu in CKEditor 4 with many items, that I hide or show based on the divs' classes. I tried to show and hide items by menu group, e.g.
editor.addMenuGroup('odt') ;
editor.addMenuItem('item_1', {
label: 'Item 1',
group: 'odt',
order: 100,
command: command_1,
} ;
// More items follow...
editor.contextMenu.addListener(function(element, selection, path) {
let rv = {} ;
// The following is just an example, my logic is more involved
rv['odt'] = CKEDITOR.TRISTATE_OFF ;
return rv ;
}) ;
This doesn't work, i.e., the items belonging to the group I return from the listener are not added to the menu.
Debugging the problem I found out with surprise that the group field in the menuItems inside the editor is set to the menu order, for example
>> Object.entries(CKEDITOR.instances)[0][1]._.menuItems.item_1.group
100
Digging in the code, I found the following surprising lines in ckeditor4/plugins/menu/plugin.js:
CKEDITOR.menuItem = CKEDITOR.tools.createClass( {
$: function( editor, name, definition ) {
[...]
// Transform the group name into its order number.
this.group = editor._.menuGroups[ this.group ];
Therefore, even without knowing if setting CKEDITOR.TRISTATE_OFF on the group name would work, I know for sure that the group name will not be used.
Am I missing something?
Did anybody ever manage to show / hide menu items in CKEditor 4 by menu groups?
Why the group name is transformed to group order in the internal data???

python bigquery script extract childjob information before query execution

following this https://cloud.google.com/bigquery/docs/samples/bigquery-query-script
we can get the child_job information after the query (parentjob) executed
but how do we extract the child_job query before it executed?
parent_job
"""
-- Declare a variable to hold names as an array.
DECLARE top_names ARRAY<STRING>;
-- Build an array of the top 100 names from the year 2017.
SET top_names = (
SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE year = 2000
);
-- Which names appear as words in Shakespeare's plays?
SELECT
name AS shakespeare_name
FROM UNNEST(top_names) AS name
WHERE name IN (
SELECT word
FROM `bigquery-public-data.samples.shakespeare`
);
"""
when this query executed it will create 2 child job:
childjob 1
SELECT STRUCT<ARRAY<STRING>>(( SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100) FROM `bigquery-public-data.usa_names.usa_1910_2013` WHERE year = 2000 )).*;
childjob 2
SELECT name AS shakespeare_name FROM UNNEST(top_names) AS name WHERE name IN ( SELECT word FROM `bigquery-public-data.samples.shakespeare` )
is there any way we can extract the child_job query before the parentjob executed?

Get the names of a dynamic product group with a subscriber in Shopware 6.1

how can I get the names of the dynamic product groups of a product?
Especially the names of that groups. The names are in the table 'product_stream_translation'.
I have a subscriber and have added this Criteria. When I am doing it like this:
$criteria->addFilter(new EqualsFilter('id', $id));
$criteria->addAssociation('streams');
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
I just got back an empty streamEntity.
#streams: Shopware\Core\Content\ProductStream\ProductStreamCollection {#11805 ▼
#elements: []
#extensions: []
}
When I am doing it like this:
$criteria->addFilter(new EqualsFilter('productId', $id));
$dynamicProductGroups = $this->productStreamMappingRepository->searchIds($criteria, $context);
I just got back the Id I put in:
product_stream_mapping
I wonder how I will get the name of the dynamic product group.
With a query I can get all the assign 'product_stream_id's from the table 'product_stream_mapping' like this:
SELECT * FROM product_stream_mapping WHERE product_id =0x000000000000000000123b313030524b
And then get the associated name of the dynamic product group. With is like this:
SELECT psm.product_id, psm.product_stream_id, p.product_number, pst.name
FROM product_stream_mapping psm
JOIN product_stream_translation pst ON pst.product_stream_id = psm.product_stream_id
JOIN product p ON p.id = psm.product_id
WHERE psm.product_id = 0x000000000000000000123b313030524b
How can I get it in the Subscriber?
Do I have to use criteria or do I have to user a repository?
This line is wrong:
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
It won't return dynamic product groups but a product collection. To get a product stream collection (dynamic product groups) replace it with:
/** #var ProductEntity $product */
$product = $this->productRepository->search($criteria, $context)->first();
$dynamicProductGroups = $product->getStreams();
Then you can read the names of the streams with:
$names = array_values(
$dynamicProductGroups->map(fn (ProductStreamEntity $productStream) => $productStream->getName())
);

Reuse code that contains variables in same script bash

I have a small block of code in bash like below
#!/bin/bash
query="select * from table where id = ${row_id}"
row_id=1
echo "$query"
row_id=3
echo "$query"
row_id=4
echo "$query"
expected output is below
select * from table where id = 1
select * from table where id = 3
select * from table where id = 5
But I am getting nothing as output
I know I am referencing variable before assigning it.
The idea here is to use reusable code instead of writing the same code at many places
How can I achieve what I want
You can create a function and call the function at various place by assign variable to it
#!/bin/bash
# create a function with variable and write your command
# here your command is print the query
my_function_name(){
arg1=$1
echo "select * from table where id = ${arg1}"
}
# assign varaible
row_id=1
# print the ourput of function when above variable is assigned
query=$(my_function_name "$row_id")
echo $query
# assign varaible
row_id=2
# print the ourput of function when above variable is assigned
query=$(my_function_name "$row_id")
echo $query
# assign varaible
row_id=3
# print the ourput of function when above variable is assigned
query=$(my_function_name "$row_id")
echo $query
you should be getting
select * from table where id =
select * from table where id =
select * from table where id =
and as you already mentioned the reason is
I know I am referencing variable before assigning it.
One way to implement this
$ for row_id in 1 3 5;
do
echo "select * from table where id = $row_id";
done
select * from table where id = 1
select * from table where id = 3
select * from table where id = 5
UPDATE
Based on the comment
Here if row_id is a random variable I get as part of another query then
how do I get the correct query as my output
which is different from the posted question, better to define a function
$ getquery() { echo "select * from table where id = $1"; }
$ getquery $RANDOM
select * from table where id = 12907

CRM 2011: Special permissions missing for Users

We have created a bunch of users in CRM 2011 using the SDK. However, we added their Security Role records through the database.
Everything seems to work fine, until these users started to save their own User Dashboards and Advanced Finds.
The users could create their own User Dashboards. However, once they created them, they could not see them. They were not in their list of Dashboards - only the System Dashboards where there.
There were no errors in the event viewer or even the trace logs.
I used SQL Profiler to see what it was doing and I discovered it was checking the PrincipalEntityMap table for principals that had an objecttypecode of 1031 - which is the User Dashboard (called UserForm).
How do these records get created?
I can write a SQL script to populate the database with these missing records.
What I would like to know is why they are missing? Any ideas?
Where do the records for PrincipalEntityMap come from?
Because we created the UserRole (i.e. User Security Role) records through the database and not through the SDK - we missed some POA (Principal Object Access) related records.
There are a number of stored procedures that can be called to re-initialise these records.
We have written a script to reset these records for all users:
-- This will create PrincipalEntityMap for users - if they are not there:
INSERT INTO PrincipalEntityMap (ObjectTypeCode, PrincipalId, PrincipalEntityMapId)
SELECT 1031, sup.PrincipalId, NEWID()
FROM SystemUserPrincipals sup
INNER JOIN SystemUser su ON su.SystemUserId = sup.SystemUserId
WHERE
(sup.PrincipalId = su.SystemUserId) AND
(sup.PrincipalId NOT IN
(
SELECT pem.PrincipalId
FROM PrincipalEntityMap pem
WHERE pem.ObjectTypeCode = 1031
)
)
DECLARE #PrincipalTable TABLE (PrincipalID uniqueidentifier)
DECLARE #CurrentPrincipalID uniqueidentifier
DECLARE #UserIds VARCHAR(60)
DECLARE #Type INT
BEGIN TRANSACTION ResetPrincipalEntitiyMap
BEGIN
SET #Type = 8
INSERT INTO #PrincipalTable (PrincipalID)
SELECT sup.PrincipalId
FROM SystemUserPrincipals sup WITH (NOLOCK)
INNER JOIN SystemUser su WITH (NOLOCK) ON sup.SystemUserId = su.SystemUserId AND sup.PrincipalId = su.SystemUserId
WHILE EXISTS (SELECT PrincipalID FROM #PrincipalTable)
BEGIN
SELECT TOP 1 #CurrentPrincipalID = PrincipalID
FROM #PrincipalTable
ORDER BY PrincipalID ASC
EXEC p_PrincipalEntityMapReinit #CurrentPrincipalID, #Type
EXEC p_PrincipalAttributeAccessMapReinit #CurrentPrincipalID, #Type
SET #UserIds = cast(#CurrentPrincipalID AS VARCHAR(50))
EXEC p_SystemUserBuEntityMapReinit #UserIds
DELETE FROM #PrincipalTable WHERE PrincipalID = #CurrentPrincipalID
END
END
COMMIT TRANSACTION ResetPrincipalEntitiyMap
Please Note: Always perform inserts/updates/deletes of Security
Related entities (User, UserRole, Team, TeamRole, etc.) through the
SDK - rather than the database. The SDK does some weird stuff in the
background that will be missed if you use SQL.
While trying to resolve the common/constant problem with exchange server side sync on CRM 2013 (error code E-Mail-Server: Crm.80044151 when sync of contacts, tasks and appoitments is enabled), we've also tried to reinit the principal-tables using your script.
For CRM2013/15, it had to be modified slightly, because the signature of SP p_PrincipalEntityMapReinit has changed.
Here's the updated TSQL - maybe it helps someone else (in our case, it didn't :( ):
DECLARE #PrincipalTable dbo.EntityIdCollection
DECLARE #CurrentPrincipalID uniqueidentifier
DECLARE #UserIds VARCHAR(60)
DECLARE #Type INT
BEGIN TRANSACTION ResetPrincipalEntitiyMap
BEGIN
SET #Type = 8
INSERT INTO #PrincipalTable (id)
SELECT sup.PrincipalId
FROM SystemUserPrincipals sup WITH (NOLOCK)
INNER JOIN SystemUser su WITH (NOLOCK) ON sup.SystemUserId = su.SystemUserId AND sup.PrincipalId = su.SystemUserId
EXEC p_PrincipalEntityMapReinit #PrincipalTable, #Type
WHILE EXISTS (SELECT id FROM #PrincipalTable)
BEGIN
SELECT TOP 1 #CurrentPrincipalID = id
FROM #PrincipalTable
ORDER BY id ASC
EXEC p_PrincipalAttributeAccessMapReinit #CurrentPrincipalID, #Type, 1
SET #UserIds = cast(#CurrentPrincipalID AS VARCHAR(50))
EXEC p_SystemUserBuEntityMapReinit #UserIds
DELETE FROM #PrincipalTable WHERE id = #CurrentPrincipalID
END
END
COMMIT TRANSACTION ResetPrincipalEntitiyMap

Resources