Formatting SQL Query Inside an IPython/Jupyter Notebook - sql

I want to show some SQL queries inside a notebook. I neither need nor want them to run. I'd just like them to be well formatted. At the very least I want them to be indented properly with new lines, though keyword highlighting would be nice too. Does a solution for this exist already?

If you set the cell as Markdown one you can write the sql query as code specifying the language (e.g. mysql)
``` mysql
SELECT *
FROM table_a AS a
LIMIT 10;
```
This produces:
It highlights the keywords. Unfortunately, it doesn't seem to deal with indentation which seems to be the main issue you are trying to deal with but maybe this helps.

If you - like me - find yourself here because you want to highlight (and run) the %%sql magic, you're best of with the technique of this answer. Posting it here cause it took me quite some time before I found the correct keywords to my answer :)
require(['notebook/js/codecell'], function(codecell) {
codecell.CodeCell.options_default.highlight_modes['magic_text/x-mssql'] = {'reg':[/^%%sql/]} ;
Jupyter.notebook.events.one('kernel_ready.Kernel', function(){
Jupyter.notebook.get_cells().map(function(cell){
if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;
});
});

I found that this fixed the issue I was having.
``` sql
Produced styled code in edit mode but not when the cell was run.
``` mysql
Produced correct styling

Related

PageNumber in Scripts for ActiveReports 7

I'm not very used to Active Reports and I got an old software using those. The software provide some kind of stripped version of Active Reports Designer 7.
I got a PageFooter section with some fields and I want to remove one to display it only when it's the last page.
Basically, what I want to do is this in scripts :
if (this.PageNumber == this.PageCount) {
Field.Visible = true;
}
I only find one post here that say this.PageNumber should work, but it dosent.
So I tried to use the ReportInfo using the FormatString as {PageNumber}, but I don't seems to be able to read the value using this.ReportInfo.Value or this.ReportInfo.Text
I also tried to make a TextBox, using SummaryType : PageCount. But I'm still unable to read the Value.
So the question is :
How can I know the Page Number and Page Count in the script section?
Or how can I read the value of those textbox I created ?
Thanks a lot!
I think these docs cover what you are looking for:
https://help.grapecity.com/activereports/webhelp/Legacy/AR7Help/OnlineEN/AddPageNumbering.html
https://help.grapecity.com/activereports/webhelp/Legacy/AR7Help/OnlineEN/index.html

PhpStorm unable to resolve column for multiple database connections

I have only been using PhpStorm a week or so, so far all my SQL queries have been working fine with no errors after setting up the database connection. This current code actually uses a second database (one is for users the other for the specific product) so I added that connection in the database tab too but its still giving me a 'unable to resolve column' warning.
Is there a way to see what database its looking at? Will it work with multiple databases? Or have I done something else wrong?
Error below:
$this->db->setSQL("SELECT T1.*, trunc(sysdate) - trunc(DATE_CHANGED) EXPIRES FROM " . $this->tableName . " T1 WHERE lower(" . $this->primaryKey . ")=lower(:id)")
Also here is what my database settings window looks like as seen some people having problems with parameter patterns causing this error but I'm fairly sure that is not the issue here:
Using PhpStorm 10.0.3
You can set the SQL resolution scope in File -> Settings -> Languages & Frameworks -> SQL Resolution Scopes.
This allows you to provide a default for the entire project and you can optionally define specific mappings to certain paths in the project.
So the short answer is that it cant read the table name as a variable even though its set in a variable above. I thought PhpStorm could work that out. The only way to remove the error would be to either completely turn off SQL inspections (obviously not ideal as I use it throughout my project) or to temporarily disable it for this statement only using the doc comment:
/** #noinspection SqlResolve */
Was hoping to find a more focused comment much like the #var or #method ones to help tell Phpstorm what the table should be so it could still inspect the rest of the statement. Something like:
/** #var $this->tableName TABLE_IM_USING */
Maybe in the future JetBrains will add that or make PhpStorm clever enough to look at the variable 3 lines above.
You can use Nowdoc/Heredoc also instead of using
/** #noinspection SqlResolve */
Here is the example
$name = "your name";
$query = <<<SQL
SELECT * FROM user WHERE name LIKE "%$name%" ORDER BY id
SQL;
Both of the methods will make the warning gone

Dojo Filtering Select Filtering

Is there a way to include the entire value in the filtering search? For example, searching “123″ would return the value “Test 123″. By default, the control only filters starting with the first character.
I tried modifying the queryExpr property mentioned here, but nothing seemed to work for me. Thanks for any tips.
I realise this is 2 years ago but I'm just answering in case someone else comes along looking!
You can specify the queryExpr like this:
<xe:djFilteringSelect id="djFilteringSelect1" value="#{viewScope.myvalue}" autoComplete="false">
<xe:this.queryExpr><![CDATA[${javascript:"*$\{0}*"}]]></xe:this.queryExpr>
<xp:selectItems id="selectItems1" value="#{myBean.mySelectItems}"/>
</xe:djFilteringSelect>

Custom Grid Query in Rally with Multiple OR Clauses

I'm trying to write a query in Rally that will show me all the defects for several projects, but every time I save the query I get the message "Could not parse: Error parsing expression -- expected ")" but saw "OR" instead."
Here is the actual query:
((((Project.Name = "Project A") OR (Project.Name = "Project B")) OR (Project.Name = "Project C")) OR (Project.Name = "Project D"))
I checked Rally's so-called Help and it seems to me that everything is set up correctly, but maybe I'm missing something?
Your query syntax and parentheses groupings look fine. I tested your exact string above in a Custom Grid and it parses fine - no "Could not parse..." error. Maybe compare the exact query you are using against your sample above? Complex AND's and OR's can definitely be frustrating. If you miss a parenthesis or spaces around operators, the query engine will complain.
fyi, I just found that doing a page reload in the browser forces the changed query expression to be evaluated, whereas simply saving the modified query does not reliably re-evaluate the changed query.
The symptom I observed was that query results continued to complain about the previous query string, even though I had replaced parts of the query with different named fields, etc. This made me suspect browser caching, and when flushing cache did not help, then I did browser page reload, which worked perfectly.
So if your browser page was reloaded between when you were having the problem and later when it started working, then this might explain why.
From About link: Rally Build: master-9274 , Browser Type: firefox/19.0, rv:19.0

Lucene query parser not parse field as expected

I want to parse a simple query using lucene (3.0.3):
title:(+return +"pink panther")
Just like in the documentation example.
The expected result is:
+title:return +title:"pink panther"
But instead i get:
+title:return +title:"itle return pink panther"
The code is very simple (c#):
Query query =
new QueryParser(
Lucene.Net.Util.Version.LUCENE_30,
"content",
new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
.Parse("title:(+return +\"pink panther\")");
I'm unable to reproduce this. Does this still occur for you?
I'm thinking that it may be some display artifacts from the output window. Is this from the Immediate Window, the Watch Window or a call to Console.WriteLine?
Sorry for the trouble, the issue was a custom-modified Lucene.Net assembly...