My error report told me that an error has occurred when an user tried uploading an empty file to my server (don't ask why the user did that - I don't know) and now I want to catch that exception which said "No data was received in the uploaded file". I wonder if there is a better way than putting a <CFTRY> around the <CFFILE action="upload"> like this:
<CFTRY>
<CFFILE action="upload" destination="#expandpath("upload")#" filefield="form.file" nameconflict="makeunique" />
<CFCATCH>
<!--- handle that error --->
</CFCATCH>
</CFTRY>
Try/Catch is the way I usually handle it.
<cftry>
<cffile action="upload" ...>
<cfcatch type="any">
<cfif Find("Saving empty (zero-length) files is prohibited", CFCatch.Detail) GT 0>
<!--- Create a zero length file on disk and continue processing as usual --->
<cffile action="write" file="..." output="">
<cfelse>
<cfrethrow>
</cfif>
</cfcatch>
</cftry>
Related
I am using 11gr2 and trying to load an XML file into a table.
Here is the code:
connected as sys:
GRANT ALL ON DIRECTORY XMLDIR TO user_1;
switch to user_1:
CREATE TABLE mytable1 (key_column VARCHAR2(10) PRIMARY KEY,
xml_column XMLType);
CREATE DIRECTORY xmldir AS 'F:\OracleTestFiles\XMLs\';
the XML file:
<PurchaseOrder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://localhost:8080/source/schemas/poSource/xsd/purchaseOrder.xsd">
<Reference>SBELL-2002100912333601PDT</Reference>
<Actions>
<Action>
<User>SVOLLMAN</User>
</Action>
</Actions>
<Reject/>
<Requestor>Sarah J. Bell</Requestor>
<User>SBELL</User>
<CostCenter>S30</CostCenter>
<ShippingInstructions>
<name>Sarah J. Bell</name>
<address>400 Oracle Parkway
Redwood Shores
CA
94065
USA</address>
<telephone>650 506 7400</telephone>
</ShippingInstructions>
<SpecialInstructions>Air Mail</SpecialInstructions>
<LineItems>
<LineItem ItemNumber="1">
<Description>A Night to Remember</Description>
<Part Id="715515009058" UnitPrice="39.95" Quantity="2"/>
</LineItem>
<LineItem ItemNumber="2">
<Description>The Unbearable Lightness Of Being</Description>
<Part Id="37429140222" UnitPrice="29.95" Quantity="2"/>
</LineItem>
<LineItem ItemNumber="3">
<Description>Sisters</Description>
<Part Id="715515011020" UnitPrice="29.95" Quantity="4"/>
</LineItem>
</LineItems>
</PurchaseOrder>
the insert statement:
INSERT INTO mytable1 VALUES ('1a', XMLType(bfilename('XMLDIR', 'PurchaseOrder.xml'), nls_charset_id('AL32UTF8')));
When I am executing the INSERT statement, I receive the following error:
Error report - ORA-22288: file or LOB operation FILEOPEN failed The
system cannot find the path specified. ORA-06512: at "SYS.XMLTYPE",
line 296 ORA-06512: at line 1
Can someone explain what is wrong, please?
Should I grant other privileges in the OS (Windows 7)?
I found the problem.
The phisically location of the directory from the hard drive was on a mapped driver (F:).
I changed it on C: and now it is working like a charm.
I'm trying to debug a cf query and cannot do this because of his complex structure.The code is following:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> --->
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
<!--- </cfif> --->
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
</cfquery>
If I run <cfdump var="#qQuery#"> it's not working nor cfoutput, I get undefined qQuery error. How can I find what query is executing behind ? I don't want to use MS SQL profiler.
Thanks,
Take everything inside the query and wrap it in a cfsavecontent instead. Output that result.
If you place the cfsavecontent inside the cfquery tags, you don't even need to worry about the cfqueryparam tags barfing, although you do need to re-output that saved content inside the query. See http://coldflint.blogspot.com/2016/01/debugging-queries-dirty-way.html
Basically, you should have this:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfsavecontent variable="sqlContent">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> --->
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
<!--- </cfif> --->
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
</cfsavecontent>
#sqlContent#
</cfquery>
<pre>#sqlContent#</pre>
Do make sure to put everything back to normal once you're done debugging.
If this question is more about HOW to debug or get some output you can work with, cftry and cfcatch are your friends.
<cftry>
---code logic---
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
</cfctry>
This should provide a complete dump of whatever errors ColdFusion encounters as well as SQL statements that were attempted, if there is indeed a syntax error generated by the loopy logic.
You have to work from the inside out this.
As I look at this query, I note that it is split on IsSimpleValue() and IsStruct(). So run this
<cfquery name="qQuery" datasource="#variables.datasource#">
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
</cfif>
</cfloop>
</cfquery>
Note that temp is never used.
The rest of the code creates <cfqueryparam>s
Conclusion
This code cannot work. It cannot create valid SQL.
Your error has nothing to do with the sql being generated by the code in the cfquery block. It's an undefined variable. If there was a problem with the code you displayed, the error message would be different.
Troublehoot as follows. First comment out all the code inside that query and replace it with:
select 1 record
This is valid for MS SQL. Leave everything else unchanged.
Running the page will produce the same error. You then have to determine why the query is not running. Likely, you have something like this going on:
<cfif some Condition is met>
run the query
</cfif>
dump the query
You'll have to determine why your condition wasn't met and make sure your page runs properly when it isn't.
The solution was to put <cftry> outside <cfloop> but not outside <cfquery>.I found that I forgot to send one parametter.
So the code is following:
<cfquery name="qQuery" datasource="#variables.datasource#">
<cftry>
<cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1">
<cfif IsSimpleValue(aSQL[i])>
<cfset temp = aSQL[i]>#Trim(DMPreserveSingleQuotes(temp))#
<cfelseif IsStruct(aSQL[i])>
<cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])>
<cfswitch expression="#aSQL[i].cfsqltype#">
<cfcase value="CF_SQL_BIT">
#getBooleanSqlValue(aSQL[i].value)#
</cfcase>
<cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">
#CreateODBCDateTime(aSQL[i].value)#
</cfcase>
<cfdefaultcase>
<cfqueryparam value="#aSQL[i].value#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#">
</cfdefaultcase>
</cfswitch>
</cfif>
</cfloop>
<cfcatch>
<cfdump var="#cfcatch#" >
</cfcatch>
</cftry>
</cfquery
I am trying to use cfpdf and keep getting the following error:
String index out of range: -1
I don't understand why. I'm running ColdFusion 11 on Debian Linux.
<CFIF FileExists("#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf")>
<cfpdfform
action="read"
source="#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf" xmldata="x"
result="r">
</cfpdfform>
<cfdump var="#x#" label="XMLData">
<cfdump var="#r#" label="Result">
<CFELSE>
File doesn't exist
</CFIF>
Exact error:
String index out of range: -1
The error occurred in /var/www/www.test.com/test.cfm: line 2
1 : <CFIF FileExists("#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf")>
2 : <cfpdfform
action="read"
source="#getDirectoryFromPath(getCurrentTemplatePath())#REPORT.pdf"
xmldata="x" result="r">
3 : </cfpdfform>
4 : <cfdump var="#x#" label="XMLData">
I have had similar issues in the past. The problem has been using non Adobe programs to create the pdf - making a pdf form in Libreoffice, for example, can cause this issue. I assume some internal formatting in the file that CF is looking for is missing.
You can try opening in Acrobat and resaving it.
Having a bit of trouble inserting a LIKE and using a wildcard within my parameter in my query using coldfusion. Here is what currently works:
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ListGetAt(selectList2,i)#" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>
My goal is to get the code somewhere where I can type in a parameter like so (but it is not working currently - Error reads cannot execute query)
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#ListGetAt(selectList2,i)#%" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>
Your syntax looks fine. I use the same kind of logic in some of my code running against Microsoft SQL Server.
Try this to debug your code and see the SQL that is being generated.
<!--- Comment out your query tag to debug <cfquery name="sample" datasource="database"> --->
<cfoutput> <!--- add a cfoutput tag to "see" your generated code --->
SELECT *
FROM table
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#ListGetAt(selectList2,i)#%" />
<cfif i neq listLen(selectList1)>AND</cfif>
</cfloop>
</cfoutput> <!--- add a cfoutput tag to "see" your generated code --->
<!--- Comment out your query tag to debug </cfquery> --->
This will most likely break the rest of your code that is dependent on the query. I usually just stick a <cfabort> tag after the closing </cfoutput> tag to stop processing and just show me the SQL.
The purpose of this is to output the generated SQL code to your browser. Look it over and see if you can spot the error. You could also copy and paste the generated SQL into your query tool (query analyzer) and test it that way.
As the title says, I've set the max length for the php error log, but it seems to keep growing much much larger than 1024. I am using the correct php.ini, I've restarted apache, etc. The permissions on the php log are 666.
As is typical for PHP, it is not really obvious from the name of the configuration setting, or even the documentation, but this directive applies to the length of a single log message, not the length of the log file as a whole.
Use logrotate or a similar tool for what you are trying to do.
Verified Pascal's initial thought:
log_errors_max_len integer
Set the maximum length of log_errors
in bytes. In error_log information
about the source is added. The default
is 1024 and 0 allows to not apply any
maximum length at all. This length is
applied to logged errors, displayed
errors and also to $php_errormsg. When
an integer is used, the value is
measured in bytes. Shorthand notation,
as described in this FAQ, may also be
used.
What the manual doesn't state is that log_errors_max_len refers only to the "body" of the error message. This means that a single line of error will still be greater than the length you set here.
To demonstrate, run this code using log_errors_max_len=0 (0 means unlimited) and log_errors=1:
<?php
// Set your server to these settings:
// error_reporting=-1
// date.timezone=utc ;to suppress the error message "It is not safe to rely on the system's timezone settings."...
echo$msg1; echo$msg2;
The bytes sent to error_log will be:
[15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg1 in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg2 in C:\index.php on line 5
Next, test the same code with log_errors_max_len=4 and log_errors=1. (Remember to restart the server.) error_log will now be:
[15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5
(Notice that your error message is prepended with "[15-Jul-2015 01:23:45 utc] PHP Notice:" and appended with "in C:\index.php on line 1", resulting in a line longer than what is set by log_errors_max_len.)
This issue occurs not just with error_log, but also with the server output sent to the client. To demonstrate, run the same code above using log_errors_max_len=4, display_errors=1, html_errors=0, error_prepend_string="PPPP", and error_append_string="AAAA". The output sent to the client is:
PPPP
Notice: Unde in C:\index.php on line 5
AAAAPPPP
Notice: Unde in C:\index.php on line 5
AAAA
Now run the same code using log_errors_max_len=4, display_errors=1, html_errors=1, error_prepend_string="PPPP", and error_append_string="AAAA". (error_prepend_string and error_append_string apply only to displayed errors, not logged errors.) The output sent to the client is:
PPPP<br />
<b>Notice</b>: Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAAPPPP<br />
<b>Notice</b>: Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAA
Also note that the above tests would return the same results even if you use ignore_repeated_errors=0. This shows that "repeated errors" are considered before the error messages are cropped.
(Your results may differ depending on the SAPI used. Above tests are done using php-5.6.7-Win32-VC11-x86 CLI on win 8.1.)