Capture File name from File Browser Item Field in Oracle Apex - forms

I want to capture file_name and store it in another item field at run time using dynamic action.
I tried it to capture File Browser Item field but its capturing entire file path.
Please suggest if this can be done using PLSQL or JS in Oracle Apex 4.2

You can use regular expression, relying on the fact that there is always a backslash before the filename:
$('#P6_FILE').val().match(/\\([^\\]*)$/)[1]
explaining the regular expression:
\\ double backslash: escaping the backlash
() parenthesis to dig out the filename from the result that initially includes backslashes
[^\\]* any letter that is not a backslash, as many times as you'd like
$ end of string
Stackoverflow sometimes escapes backslashes itself, so this might look messy

$('#P6_FILE').val().match(/\([^\]*)$/)[1]
this has worked in DA set value

I use this SQL to get the file name from the file browser :
select filename
FROM apex_application_temp_files
where name = :P2_FILE_SELECT;
P2_FILE_SELECT is the file browser item.
Write this SQL into "SQL Query" of SOURCE.

Related

postgresql - pgloader - quotes handling

I am new to postgresql and just starting to use it. I am trying to load a file into a table and facing some issues.
Sample data - the file file1.RPT contains data in the below format
"Bharath"|Kumar|Krishnan
abc"|def|ghi
qwerty|asdfgh|lkjhg
Below is the load script that is used
LOAD CSV
INTO table1
....
WITH truncate,
fields optionally enclosed by '"',
fields escaped by '"'
fields terminated by '|'
....
However, the above script is not working and is not loading any data into the table. I am not sure whats the issue here. My understanding is that first row data has to be successfully loaded (since I have given optionally enclosed by) and the second row also must be loaded (since I am trying to escape the double quote).
Request help in getting the same rectified.
Thank you.
We cannot escape and optionally quote the same character. If the double-quote will be part of the data, then it can be ignored using field not enclosed option. The default option is field optionally enclosed by double-quote.
Apparently, you're not escaping the quote in the second row, because either you must use a backslash (or another quoting character) before:
abc\"|def|ghi
or you should enclose the entire line with quote
another alternative is to accept to have quotes in the first field, then you should use the following:
fields not enclosed
in your load script

Single quotes stored in a Postgres database

I've been working on an Express app that has a form designed to hold lines and quotes.
Some of the lines will have single quotes('), but overall it's able to store the info and I'm able to back it up and store it without any problems. Now, when I want do pg_dump and have the database put into an SQL file, the quotes seem to cause some things to appear a bit wonky in my text editor.
Would I have to create a method to change all the single quotation marks into double, or can I leave it as is and be able to upload it back to the database without causing major issues. I know people will continue to enter in lines that contain either single or double quotations, so I would like to know any solution or answer that would help greatly.
Single quotes in character data types are no problem at all. You just need to escape them properly in string literals.
To write data with INSERT you need to quote all string literals according to SQL syntax rules. There are tools to do that for you ...
Insert text with single quotes in PostgreSQL
However, pg_dump takes care of escaping automatically. The default mode produces text output to be re-imported with COPY (much faster than INSERT), and single quotes have no special meaning there. And in (non-default) csv mode, the default quote character is double-quote (") and configurable. The manual:
QUOTE
Specifies the quoting character to be used when a data value is quoted. The default is double-quote. This must be a single one-byte character. This option is allowed only when using CSV format.
The format is defined by rules for COPY and not by SQL syntax rules.

Uploading data to RedShift using COPY

I am trying to upload data to RedShift using COPY command.
On this row:
4072462|10013868|default|2015-10-14 21:23:18.0|0|'A=0
I am getting this error:
Delimited value missing end quote
This is the COPY command:
copy test
from 's3://test/test.gz'
credentials 'aws_access_key_id=xxx;aws_secret_access_key=xxx' removequotes escape gzip
First, I hope you know why you are getting the mentioned error: You have a a single quote in one of the column values. While using the removequotes option, Redshift documentation clearly says that:
If a string has a beginning single or double quotation mark but no corresponding ending mark, the COPY command fails to load that row and returns an error.
One thing is certain: removequotes is certainly not what you are looking for.
Second, so what are your options?
If preprocessing the S3 file is in your control, consider using the escape option. Per the documentation,
When this parameter is specified, the backslash character (\) in input data is treated as an escape character.
So your input row in S3 should change to something like:
4072462|10013868|default|2015-10-14 21:23:18.0|0|\'A=0
See if the CSV DELIMITER '|' works for you. Check documentation here.

How to search parentheses, brackets using FULL TEXT INDEXING

I have been fighting this issue for a while
I would like to use a FULL Text Seach query to find Files on a windows file system.
The problem is when the case comes up where there is a parentheses in the file name.
This example was created from a copy being pasted in the same location as the original a few times.
Here is my code:
DECLARE #SearchWord VARCHAR(50)
SET #SearchWord = '"KAP1556PP_P01(2).jpg"'
SELECT
[FileName],
[FilePath]
FROM
[dbo].[tblLegalPlan]
WHERE
CONTAINS(*, #SearchWord)
When I use Double quotes for the #Searchword I recieve no results.
When I use no quotes for the #Searchword I recieve an error message:
Msg 7630, Level 15, State 2, Line 8
Syntax error near '(' in the full-text search condition 'KAP1556PP_P01(2).jpg'.
When I search for files containing TEXT up to the bracket i Get undesrired results obviously:
SET #SearchWord = '"KAP1556PP_P01*"'
Results
FileName FilePath
KAP1556PP_P01(1).jpg BC\EPP\KAP
KAP1556PP_P01(2).jpg BC\EPP\KAP
Any and all iterations of the above show to not be usefull.
There are many articles of people trying to parse the search terms and work it out, but I have not come accross any that can handle this situation.
A solution would be appreciated.
Thanks
The work around to this for me was to execute a Stored Procedure that would remove and/or replace the brackets in question, allowing the FULL TEXT indexing to work.

SQLite update to change double-double quotes ("") to regular quotation marks (")?

working on an iPhone app. I just imported some records into a SQL Lite database, and all my regular quote marks have been "doubled". An example:
Desired final format:
The song "ABC" will play at 3 PM.
The record is currently appearing in the database as:
The song ""ABC"" will play at 3 PM.
Does anyone know how to do a SQL update to change all "double-double" quotes to just regular quotation marks?
Just to clarify, I'm looking directly at the database, not via code. The code will just display these as "double-double" quotes just as they appear in the database, so I want to remove them. The "double-double" quotes are actually in the import file as well, but if I try to remove them, then the import fails. So I kept them there, and now that the records are successfully imported into the database, now I just want to correct the "double-double" quote thing with a mass SQL update if it's possible. Thanks in advance for any insight!
SQLite uses single quotes to escape string literals. It escapes single quotes by adding another single quote (likewise for double quotes). So technically as long as your SQL is well constructed, the import process should work properly. The strings should be enclosed in single quotes, and not double quotes. I suspect that your code may be constructing the SQL by hand instead of binding/properly escaping the values.
SQLite has a built in function to quote string's. It's called quote. Here are some sample inputs, and the corresponding output:
sqlite> SELECT quote("foo");
'foo'
sqlite> SELECT quote("foo ""bar""");
'foo "bar"'
sqlite> SELECT quote("foo 'bar'");
'foo ''bar'''
So you could remove the twice escaped double quote before it even goes to SQLite using NSString methods.
[#"badString\"\"" stringByReplacingOccurrencesOfString:#"\"\"" withString:#"\""];
If the database already contains bad values, then you could run the following update SQL to clean it up:
UPDATE table SET column = REPLACE(column, '""', '"');