How to apply an intention to a whole file - intellij-idea

I have a large SQL file where the identifiers are not quoted. IntelliJ IDEA suggest the intention to "Quote identifier". I can do this one by one but this is very cumbersome since I have a lot of different identifiers there (database names, table names, fields).
Using the Analyze/Run inspection by name command, I can select the "Identifier should be quoted" analysis to my whole file. But this analysis does not yield any result for some unknown reason. The result of the analysis is "No suspicious code found".
I also defined an exact scope of the files I want to apply the intention on, but it didn't help - same result.
How can I achieve the application of the intention multiple times at once?

I don't know how to apply intentions actions in batch (I don't even know if this is possible), but for your problem you can do:
Open Settings > Editor > SQL. In the general tab, find the option Identifier quotation and set it to Quote. Click apply.
Open your file and reformat it (Code > Reformat Code or Ctrl+Alt+L).
It should normally add quotes to all the identifiers in the file.

Related

Sanitizing User Input

I'm writing an R application in which I'm interacting with a SQL database using the RODBC package. I'm looking up items in the database based on columns in a .csv file. Although I have no reason to expect malicious content in these files, I'd much rather be safe than sorry.
How do you sanitize user input for use in a SQL query in R? In most languages I've come across, there were libraries that would accept a string, and return a sanitized string back to you. Does anything like that exist in R?
You could always use regular expressions to construct an accepted pattern and remove the cases that don't match.
I'd try that to be in full control. Don't know of any ready made checks.

how to update field names automatically after updating SQL

I am changing the command text for a data set inside the .rdl ffile:
I would like to know how can I update the resulting fields that are returned by the select statement:
I know that these fields must be automatically generated, so I was wondering if it's possible to update them right after editing the SQL code inline??
Usually when someone wants to have a look at the data in command text they are wanting it for reference to an end user(from what I have seen). You may want to amend it but ultimately with reporting your first goal should be: "What am I doing this for?" If your goal is dynamic creation at runtime then I would avoid this and offer a few other suggestions:
Procertize it. Making a stored procedure if you have the know how in SQL Server is a convenient and fast way to get what you want and you can optimize it if you know what you are doing with your SQL FU to get good results. The downside would be if you work with multiple environments you have to deploy your code for the TSQL as well as the RDL file.
Use an expression to build the dataset at runtime. In cases where I have been told that the query itself was not properly optimized by other developers they have mentioned doing this. I myself do not always see the advantage of doing this versus just having your predicate construction work well with good indexing on the source engine. Regardless you can build your dataset at runtime. It would be similar to hitting 'fx' next to the text and then putting in something like this(assuming you have a variable named #Start):
="Select thing
from table
Where >= " & Parameters!Start.Value
Again I have not really seen if this is really that much faster than:
Select thing
from table
Where >= #Start
But it is there if you just want to build it dynamically.
You can try to build your expression dynamically from parameters being PART of the select statement. SSRS is all about the 'expressions' and what you can do with them. Once you jump in and learn how they apply to everything you can go nuts so to speak on using them. A general rule though is the more of them you use and rely on the slower your reports will become.
I hope some of this may help, I would ask first is something dynamic due to a need to be event driven or is performance related.

Sql ant task versus sqlplus: reserver word "rem"

I have a problem with sql ant taks with my build.xml.
I use task in ant and creating a table with column name "rem" fails. I am guessing this is a reserved word in Oracle. However, I have two questions regarding this issue:
This problem diesn't occur in sqlplus. i.e.: It lets me create a table with column name "rem".
Should I be concerened about reserved words that aren't of Oracle. For example: "go" in mysql?
Thnak you.
I don't think you need to worry about MySQL reserved words unless you are intending on using both RDBMS.
However, to address your second point first:
While cagcowboy's answer tells you how to fix the problem I can only ask that you do not do this.
I something has to be enclosed in double quotes then you have to remember to do that everywhere. Some UIs ( e.g. Toad ) require special options to be initialised.
Effectively it's a massive amount of hassle and as Dems and Davd Faber have commented can be massively confusing.
Incidentally go does seem to be a reserved work in Oracle, no idea what it does though.
To address your first bullet point rem isn't actually a reserved word in Oracle - only SQL*Plus- and creating a table with rem as a column name works because of this. Your specific problem must be a something to do with ant.
Try putting the column in double quotes...
"REM"

Excel VBA: Best way to work with data of CSV file

I am looking for a direct and efficient method to read out csv-files and handily work with the data in Excel/VBA?
The best thing would be: direct access of data by specifying row and column. Can you tell me of your preferred option? Do you know an additional option to the following two?
A: Use Workbooks.Open or Workbooks.OpenText to open the csv-file as a workbook. Then work with the workbook (compare this thread).
B: Use Open strFilename For Input As #1 to write the data into a string. Work with the string (compare this thread).
Thanks a lot!
==========EDIT=========
Let me add what I have learned from your posts so far: The optimal option to do the task depends too much on what you want to do exactly, thus no answer possible. Also, there are the following additional options to read csv files:
C: Use VBScript-type language with ADO (SQL-type statements). I still am figuring out how to create a minimal example that works.
D: Use FileSystemObject, see e.g. this thread
The fastest and most efficient way to add CSV data to excel is to use Excel's text import wizard.
This parses CSV file, giving you several options to format and organize the data.
Typically, when programming one's own CSV parser, one will ignore the odd syntax cases, causing rework of the parsing code. Using the excel wizard covers this and gives you some other bonuses (like formatting options).
To load csv, (in Excel 2007/2010) from the "data" tab, pick "From Text" to start the "Import Text Wizard". Note the default delimiter is tab, so you'll need to change it to comma (or whatever character) in step 2.

I need to split a text field into 2 fields in access 2007

I have inherited a really bad access database that I need to move the data out of it into a MySQL database. I have a field that has some string data in it followed by an oddly formatted date in parentheses at the end. I am trying to craft a query that has a field that contains only the string up to the open parenthese "(". And a second field that contains only the contents of the parentheses.
Following advice I have found here and elsewhere I have tried
note: Left(notefield, InStr(notefield, "("))
but I get the error "Undefined function 'left' in expression." even though I built it using the Builder. So any ideas what I should use in my access query to extract this data? And it has to be in access.
VB(A) is funny this way (I say it that way because this same problem shows up in VB6 as well as the VBA in Office applications)....
When built-in functions such as Left, 'right$, InStr, &c. start throwing "Undefined Function" errors, it almost always means that you've got a problem with References. Some library that you have defined a reference to is missing or broken, and it's not necessarily the one that's reporting errors.
Check Tools | References... and make sure that nothing that's checked says it's "MISSING". If it is, either remove it or fix the link (you can Browse... to the .dll file if you know where it's stored).