Coldfusion Creating Random SQL Queries

Here is an error I received from one of our sites:
Syntax error or access violation: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'WHERE user_id = '19152'
AND paid = 0' at line 1
Here is the generated sql it tried to run:
SELECT SUM(hours) AS totalHours FROM records WHERE user_id =
'19152' WHERE user_id = '19152' AND paid = 0
Obviously there is two where statements.
Now look at the method that generated this:
<cffunction name="GetTotalUnpaidHours" access="public"
returntype="numeric" output="false">
<!--- Get total sum of unpaid hours
--------------------------------------------------->
<cfscript>
sql = "SELECT SUM(hours) AS totalHours ";
sql = sql & "FROM records ";
sql = sql & "WHERE user_id = '#variables.user_id#' ";
sql = sql & "AND paid = 0";
hours = SqlQuery(sql);
if ( IsNumeric(hours.totalHours) ) return hours.totalHours;
else return 0;
</cfscript>
</cffunction>
This is about as simple as it gets. Build an SQL string, pass
it to the SqlQuery() method with just globally available wrapper of
the CFQUERY tag, and return the result.
How and why would it append the WHERE statement twice. This
is not the first error like this from our high traffic production
site. 99% of the time it works as this method is called 1000's of
times a day by 1000's of users going in and out of their account
every all day. It is not limited to just this example as I've seen
similar instances of this happening with incorrect queries all over
the app. Tested and retested the code and have never been able to
reproduce these types of results.
Any comments or suggestions would be greatly appreciated.
It's essential that this application be 100% reliable.
Anthony

WebPexDev,
Interesting. Dan Bracuk could be right about it being a scope
problem. If the sql variable isn't local to the function I can
kindof see how you might end up with two where clauses in the sql
string.
> Build an SQL string, pass it to the SqlQuery() method
with just globally available
> wrapper of the CFQUERY tag, and return the result.
Assuming the functions are contained in a cfc, is the cfc
stored in the session or application scope?

Similar Messages

  • Using coldfusion variables in sql queries, some unexpected results.

    I've come across a somewhat perplexing problem. I'd be
    interested to see if the following works for other people:
    <cfset sql_var = "'something','something else'">
    <cfquery name="test" datasource="db">
    select id from table where somename in (#sql_var#)
    </cfquery>
    As it is this produces a sql error - coldfusion tries to run
    the query as
    select id from table where somename in
    (''something'',''something else'')
    That's with double single quotes around each of the strings,
    even though this wasn't specified in the variable sql_var.
    So I tried this:
    <cfset sql_var = "something','something else">
    <cfquery name="test" datasource="db">
    select id from table where somename in ('#sql_var#')
    </cfquery>
    Where variable sql_var only has single quotes in between the
    two strings, and I've added single quotes to the select statement.
    This produces no error, but no results either. The sql being run is
    select id from table where somename in
    ('something','something else')
    Which is exactly as it should be. I copy and paste the exact
    same query into the database and it produces results - but when
    coldfusion runs the query it doesn't. Running the query with no
    quotes produces a sql error, which is what I wopuld expect.
    Which leaves me somewhat at a loss. Anyone got any ideas?
    Running CF 6.1 (I think) using a MySQL database, if that
    makes any difference to anything.

    That's with double single quotes around each of the strings,
    even though this wasn't specified in the variable sql_var.
    In Coldfusion, 'something' and "something" are the same
    thing. You should expect that Coldfusion could switch from one to
    the other.
    Where variable sql_var only has single quotes in between the two
    strings, and I've added single quotes to the select statement. This
    produces no error, but no results either. The sql being run is
    select id from table where somename in
    ('something','something else')
    I don't think that is the query being run. Before passing the
    string, "something','something else", to the query Coldfusion will
    automatically escape the single-quotes on either side of the comma.
    That is the default behaviour. The resulting query is
    select id from table where somename in
    ('something'',''something else')
    To avoid these complications, use the function
    PreserveSingleQuotes(). Thus,
    <cfset sql_var = "'something','something else'">
    <cfquery name="test" datasource="db">
    select id from table where somename in
    (#preservesinglequotes(sql_var)#)
    </cfquery>

  • Problem occured when create a tree table for master-detail view objects using SQL queries?

    I am programming a tree table for master-detail view objects using SQL queries and these 2 view objects are not simple singel tables queries, and 2 complex SQL are prepared for master and view objects. see below:
    1. Master View object (key attribute is SourceBlock and some varaible bindings are used for this view object.)
    SELECT  cntr_list.SOURCE_BLOCK,                   
            sum(                   
             case when cntr_list.cntr_size_q = '20'                   
                  then cntr_list.cntr_qty                   
                  else 0 end ) as cntr20 ,                   
            sum(                   
             case when cntr_list.cntr_size_q = '40'                   
                  then cntr_list.cntr_qty                   
                  else 0 end ) as cntr40 ,                   
             sum(                   
             case when cntr_list.cntr_size_q = '45'                   
                  then cntr_list.cntr_qty                   
                  else 0 end ) as cntr45                    
    FROM (       
        SELECT yb1.BLOCK_M as SOURCE_BLOCK,       
               scn.CNTR_SIZE_Q,        
               count(scn.CNTR_SIZE_Q) AS cntr_qty        
        FROM  SHIFT_CMR scm, SHIFT_CNTR scn, YARD_BLOCK yb1, YARD_BLOCK yb2       
        WHERE       
        scm.cmr_n = scn.cmr_n             
        AND (scm.plan_start_dt BETWEEN to_date(:DateFrom,'YYYY/MM/DD HH24:MI:SS') AND to_date(:DateTo,'YYYY/MM/DD HH24:MI:SS')                 
        OR scm.plan_end_dt BETWEEN to_date(:DateFrom,'YYYY/MM/DD HH24:MI:SS') AND to_date(:DateTo,'YYYY/MM/DD HH24:MI:SS'))                 
        AND scm.shift_mode_c = :ShiftModeCode                           
        AND scm.end_terminal_c = :TerminalCode      
        AND scm.start_terminal_c = yb1.terminal_c                  
        AND scm.start_block_n = yb1.block_n                  
        AND substr(scn.start_location_c,(instr(scn.start_location_c,',',1,5)+1),instr(scn.start_location_c,',',1,6)-(instr(scn.start_location_c,',',1,5)+1)) BETWEEN yb1.slot_from_n AND yb1.slot_to_n                  
        AND scm.end_terminal_c = yb2.terminal_c                  
        AND scm.end_block_n = yb2.block_n                  
        AND substr(scn.end_location_c,(instr(scn.end_location_c,',',1,5)+1),instr(scn.end_location_c,',',1,6)-(instr(scn.end_location_c,',',1,5)+1)) BETWEEN yb2.slot_from_n AND yb2.slot_to_n           
        AND scn.status_c not in (1, 11)             
        AND scn.shift_type_c = 'V'             
        AND scn.source_c = 'S'       
        GROUP BY yb1.BLOCK_M, scn.CNTR_SIZE_Q       
    ) cntr_list       
    GROUP BY cntr_list.SOURCE_BLOCK
    2. Detail View object (key attributes are SourceBlock and EndBlock and same varaible bindings are used for this view object.)
    SELECT  cntr_list.SOURCE_BLOCK, cntr_list.END_BLOCK,                
            sum(                     
             case when cntr_list.cntr_size_q = '20'                     
                  then cntr_list.cntr_qty                     
                  else 0 end ) as cntr20 ,                     
            sum(                     
             case when cntr_list.cntr_size_q = '40'                     
                  then cntr_list.cntr_qty                     
                  else 0 end ) as cntr40 ,                     
             sum(                     
             case when cntr_list.cntr_size_q = '45'                     
                  then cntr_list.cntr_qty                     
                  else 0 end ) as cntr45                      
    FROM (         
        SELECT yb1.BLOCK_M as SOURCE_BLOCK,     
               yb2.BLOCK_M as END_BLOCK,  
               scn.CNTR_SIZE_Q,          
               count(scn.CNTR_SIZE_Q) AS cntr_qty          
        FROM  SHIFT_CMR scm, SHIFT_CNTR scn, YARD_BLOCK yb1, YARD_BLOCK yb2         
        WHERE         
        scm.cmr_n = scn.cmr_n               
        AND (scm.plan_start_dt BETWEEN to_date(:DateFrom,'YYYY/MM/DD HH24:MI:SS') AND to_date(:DateTo,'YYYY/MM/DD HH24:MI:SS')                   
        OR scm.plan_end_dt BETWEEN to_date(:DateFrom,'YYYY/MM/DD HH24:MI:SS') AND to_date(:DateTo,'YYYY/MM/DD HH24:MI:SS'))                   
        AND scm.shift_mode_c = :ShiftModeCode                             
        AND scm.end_terminal_c = :TerminalCode        
        AND scm.start_terminal_c = yb1.terminal_c                    
        AND scm.start_block_n = yb1.block_n                    
        AND substr(scn.start_location_c,(instr(scn.start_location_c,',',1,5)+1),instr(scn.start_location_c,',',1,6)-(instr(scn.start_location_c,',',1,5)+1)) BETWEEN yb1.slot_from_n AND yb1.slot_to_n                    
        AND scm.end_terminal_c = yb2.terminal_c                    
        AND scm.end_block_n = yb2.block_n                    
        AND substr(scn.end_location_c,(instr(scn.end_location_c,',',1,5)+1),instr(scn.end_location_c,',',1,6)-(instr(scn.end_location_c,',',1,5)+1)) BETWEEN yb2.slot_from_n AND yb2.slot_to_n             
        AND scn.status_c not in (1, 11)               
        AND scn.shift_type_c = 'V'               
        AND scn.source_c = 'S'         
        GROUP BY yb1.BLOCK_M, yb2.BLOCK_M, scn.CNTR_SIZE_Q         
    ) cntr_list         
    GROUP BY cntr_list.SOURCE_BLOCK, cntr_list.END_BLOCK
    3. I create a view link to create master-detail relationship for these 2 view objects.
    masterview.SourceBlock (1)->detailview.SourceBlock (*).
    4. I create a tree table using these 2 view objects with master-detail relationship.
    When I set default value for variable bindings of these 2 view objects and the matching records exist, tree table can work well. I can expand the master row to display detail row in UI.
    But I need to pass in dymamic parameter value for variable bindings of these 2 view objects, tree table cannnot work again. when I expand the master row and no detail row are displayed in UI.
    I am sure that I pass in correct parameter value for master/detail view objects and matching records exist.
    Managed Bean:
            DCIteratorBinding dc = (DCIteratorBinding)evaluteEL("#{bindings.MasterView1Iterator}");
            ViewObject vo = dc.getViewObject();
            System.out.println("Before MasterView1Iterator vo.getEstimatedRowCount()="+ vo.getEstimatedRowCount());
            System.out.println("Before MasterView1Iterator ShiftModeCode="+ vo.ensureVariableManager().getVariableValue("ShiftModeCode"));
            vo.ensureVariableManager().setVariableValue("DateFrom", dateFrom);
            vo.ensureVariableManager().setVariableValue("DateTo", dateTo);
            vo.ensureVariableManager().setVariableValue("ShiftModeCode", shiftModeC);
            vo.ensureVariableManager().setVariableValue("TerminalCode", terminalCode);
            vo.executeQuery();
            System.out.println("MasterView1Iterator vo.getEstimatedRowCount()="+ vo.getEstimatedRowCount());
            DCIteratorBinding dc1 = (DCIteratorBinding)evaluteEL("#{bindings.DetailView1Iterator}");
            ViewObject vo1 = dc1.getViewObject();
            System.out.println("Before DetailView1Iterator vo1.getEstimatedRowCount()="+ vo1.getEstimatedRowCount());
            System.out.println("Before DetailView1Iterator ShiftModeCode="+ vo1.ensureVariableManager().getVariableValue("ShiftModeCode"));
            vo1.ensureVariableManager().setVariableValue("DateFrom", dateFrom);
            vo1.ensureVariableManager().setVariableValue("DateTo", dateTo);
            vo1.ensureVariableManager().setVariableValue("ShiftModeCode", shiftModeC);
            vo1.ensureVariableManager().setVariableValue("TerminalCode", terminalCode);
            vo1.executeQuery();
            System.out.println("after DetailView1Iterator vo1.getEstimatedRowCount()="+ vo1.getEstimatedRowCount());
    5.  What's wrong in my implementation?  I don't have no problem to implement such a tree table if using simple master-detail tables view object, but now I have to use such 2 view objects using complex SQL for my requirement and variable bindings are necessary for detail view object although I also think a bit strange by myself.

    Hi Frank,
    Thank you and it can work.
    public void setLowHighSalaryRangeForDetailEmployeesAccessorViewObject(Number lowSalary,
                                                                              Number highSalary) {
            Row r = getCurrentRow();
            if (r != null) {
                RowSet rs = (RowSet)r.getAttribute("EmpView");
                if (rs != null) {
                    ViewObject accessorVO = rs.getViewObject();
                    accessorVO.setNamedWhereClauseParam("LowSalary", lowSalary);
                    accessorVO.setNamedWhereClauseParam("HighSalary", highSalary);
                executeQuery();
    but I have a quesiton in this way. in code snippet, it is first getting current row of current master VO to determine if update variables value of detail VO. in my case, current row is possibly null after executeQuery() of master VO and  I have to change current row manually like below.
    any idea?
                DCIteratorBinding dc = (DCIteratorBinding)ADFUtil.evaluateEL("#{bindings.SSForecastSourceBlockView1Iterator}");
                ViewObject vo = dc.getViewObject();           
                vo.ensureVariableManager().setVariableValue("DateFrom", dateFrom);
                vo.ensureVariableManager().setVariableValue("DateTo", dateTo);
                vo.ensureVariableManager().setVariableValue("ShiftModeCode", shiftModeC);
                vo.ensureVariableManager().setVariableValue("TerminalCode", terminalCode);
                vo.executeQuery();
                vo.setCurrentRowAtRangeIndex(0);
                ((SSForecastSourceBlockViewImpl)vo).synchornizeAccessorVOVariableValues();

  • Developing portlets for dummies (sql queries)

    Hello, I've been trying to build a dynamic menu. First I went with just plain old plsql: i created a function in the portal schema that returns an unordered, nested list of the pages in my pagegroup and called that function in a regular pl/sql item on my portal page. I did this by querying the wwpob_page$ table and that went just great in my test&development setup (of which I am the admin of course :))
    Then I realized that since I'm not an administrator of the server hosting our portal and I only have very limited privileges (I am only a page group administrator) I will probably not be allowed to utilize this function nor will they agree to install it in the portal schema, and I decided I should build a portlet that does the same thing (so it can be registered and so on, and so it can use the synonyms and tools that are available to registered providers). There already is such a portlet (and provider) registered for use in the target portal, but I don't like it because i uses tables and hard-coded styles so I will cook my own, better version. :)
    So I downloaded an example portlet and am getting the hang of it, but now I just can't for the life of me figure out how to enable any sql-queries. I have run the provsyns-.sql script, logged in as test_provider/portal and installed my portlet-package as test_provider user. I can see the available pl/sql packages in Toad, but there are no tables or views for me to to see. That means I can't query the portal tables that I need to.
    edit: ok, stupid user error; I suck at using Toad, so I was looking at the wrong schema altogether :D So now i see the public views and packages, so forget that bit of the question.
    But still, I cannot see even wwsbr_all_folders -view, much less the wwpob_page$ -table. I cannot see any way to find the pages that are in my page group. Somehow it must be doable, right?
    Have I done something wrong, missed a step in enabling my test-provider / schema perhaps? I don't really know what I'm doing, but I followed instructions here: http://home.c2i.net/toreingolf/oracle/portal/my_first_plsql_portlet.htm (excellent instructions, thanks!)
    So should my portlet be able to access those tables or not? How the heck has the third partly portlet maker done it?
    i'm on OracleAS Portal 10g Release 2 (10.1.4)
    Edited by: Baguette on 23-Apr-2009 05:13
    Edited by: Baguette on 23-Apr-2009 05:32

    i see your perspective now. and let me give a perspective to my first reply too.
    what i proposed to you was the answer of what i quoted in the message. that is, why didn't you see those views in the new schema you created! and it is still ok but it is done in the portal schema for which you should have privielges too and i assumed you had. my mistake!
    now, i can relate your privacy concerns with your earlier message:
    Hello, I've been trying to build a dynamic menu. First I went with just plain old plsql: i created a function in the portal schema that returns an unordered, nested list of the pages in my pagegroup and called that function in a regular pl/sql item on my portal page. I did this by querying the wwpob_page$ table and that went just great in my test&development setup (of which I am the admin of course :))
    +Then I realized that since I'm not an administrator of the server hosting our portal and I only have very limited privileges (I am only a page group administrator) I will probably not be allowed to utilize this function nor will they agree to install it in the portal schema, and I decided I should build a portlet that does the same thing (so it can be registered and so on, and so it can use the synonyms and tools that are available to registered providers). There already is such a portlet (and provider) registered for use in the target portal, but I don't like it because i uses tables and hard-coded styles so I will cook my own, better version. :)+
    +So I downloaded an example portlet and am getting the hang of it, but now I just can't for the life of me figure out how to enable any sql-queries. I have run the provsyns-.sql script, logged in as test_provider/portal and installed my portlet-package as test_provider user. I can see the available pl/sql packages in Toad, but there are no tables or views for me to to see. That means I can't query the portal tables that I need to.+
    - by downloading an example portlet, you probably mean you created a new schema. because provsyns work on a schema.
    - if you are not the administrator of the portal, and may not be able to access some portions of the portal, it means that you do not use the portal user (the user which serves as the owner of the portal schema).
    - now, your plan to create a new schema and give those privielges would still not work. because, by creating a new schema you cannot sneak in to the oriignal portal schema if you do not have privileges to do it. obvious, right? otherwise, it would be a vulnerability of the software that you can see what you are not allowed to see by creating a new schema.
    - however, there is a bright side here. the views give records based on your privileges.
    - so if your administrators have generated them already or if they generate on the original portal schema, then you may see the pages and items that you have privileges to see and no more.
    so now, you may ask the administrators if they have already done it, and if not, then if they would be willing to do it.
    hope that helps!
    AMN

  • SQL queries in JSP

    Does anyone know how to create a JSP which allows the user to input data into a simple database and then allow the user to input SQL queries? I can do this in a servlet but must hard code the query. It would be great to be able to type in differnet queries to see the results.
    Thanks
    Michael

    hai,
    I am giving u a small example which allows user to enter data in the html page and the same is submitted by the Jsp page in the database.
    <%@ page language="java" import="java.sql.*" %>
    <html>
    <body bgcolor="#FFd08d" >
    <%!     Connection conn;
         Statement st,st1;
         ResultSet rs,rs1;
         int i,j;
    %>
    <%     
         try{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              conn=DriverManager.getConnection("jdbc:odbc:--DSNName--","--DataBaseUserName--","--DataBasePassword--");
         catch(Exception e)
    %>
         Error in Saving : <%=e%>
    <%
         try
         String email_address=request.getParameter("email_address");
         String query_text=request.getParameter("query_text");     
         PreparedStatement st=null;
         String inst="insert into databasename..DataBaseTableName(email_address,query_text) values (?,?)";
         st=conn.prepareStatement(inst);
         st.setString(1,email_address);
         st.setString(2,query_text);
         st.executeUpdate();
         conn.close();
    %>
    Your query is Submitted.<br>
    Thanks.
    <%
         catch(SQLException e)
    %>
    Error in Saving : <%=e%>
    <%
    %>          
    </body>
    </html>
    I think this will solve ur query.
    bye
    sameer

  • [DW 8.02 + PHP] how to use variables in advanced SQL queries

    Hi all,
    I can't find a way to use variables in an SQL query after
    updating
    dreamweaver 8.02.
    I always get error messages that says: 'missing variable
    type:myvariablename', undefined#myvariablename... and so on.
    What is the correct way to use variables?
    I usually set a variable in a PHP statement (example: <?
    $today=date('Y-m-d'); ?>)
    and then I compare this variable in the SQL query.
    What is the correct syntax for variable in DW 8.02 in
    advanced SQL
    queries?
    TIA
    tony

    sweetman wrote:
    > I'm editing a website created with DW 8.01 and MX
    Kollection.
    >
    > I updated DW to 8.02 and now I can't edit an existing
    SQL query.
    > I always get an error message 'Missing variable type'
    and I can't go
    > on.
    InterAKT released a new version of Kollection to cope with
    the 8.0.2
    changes. AFAIK, you should be able to download the updated
    version from
    your InterAKT account area.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • SQL Queries don’t recognize Package member variables.

    Hi,
    I have a package defined like this:
    CREATE OR REPLACE PACKAGE PROD.PKG_BSYS_COMMON
    AS
    MAX_RETURN_ROWS NUMBER(6) :=1000;
    END PKG_BSYS_COMMON;
    The problem is that I cannot use MAX_RETURN_ROWS in my SQL queries:
    SELECT
    FROM
    CLIENT
    WHERE
    ROWNUM < PROD.PKG_BSYS_COMMON.MAX_RETURN_ROWS
    Is there any way to use that package member variable in my queries?
    This is a simplified explanation of our problem and it is very important for our business to avoid hardcoding constants in queries and define all of them in a central location. Is there a better way doing this?
    Any help would be appreciated,
    Alan

    CREATE OR REPLACE PACKAGE PKG_BSYS_COMMON
    AS
    function max_return_rows return number ;
    END PKG_BSYS_COMMON;
    CREATE OR REPLACE PACKAGE body PKG_BSYS_COMMON  as
    function max_return_rows return number is
    begin
    return(1000);
    end;
    end PKG_BSYS_COMMON;
    select pkg_bsys_common.max_return_rows from dual;
    MAX_RETURN_ROWS
               1000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can I use Microsoft SQL Server Management Studio version 11.0 to write SQL queries for "SQL Server Compact 4.0 Local Database"

    Hi, Can I use Microsoft SQL Server Management Studio version 11.0 to write SQL queries for "SQL Server Compact 4.0 Local Database" ?
    When I use Connect Object Explorer, the "Connect to Server" dialog box which pops up has only 4 selections in the Server Type Drop Down List. They are Database Engine, Analysis Services, Reporting Services & Integration Services. I have read
    somewhere that there should be a compact database option. but I do not see it.
    What I would like to do is use free form SQL Queries against the tables in "SQL Server Compact 4.0 Local Database" .
    Once I have validated these queries, then I will use them in my Visual Studio 2012 C#, ASP.NET application. I created the Local Database using Visual Studio 2012 for use by my application.
    Thank you for your help..
    diana4

    Hello,
    With SSMS 2005 we have had the Option to work with SQL CE database files, but not with higher Version of SSMS.
    You can use the free SQL CE Toolbax instead; see
    http://sqlcetoolbox.codeplex.com/
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Monitoring Oracle SQL queries in VBA

    I currently use VBA with Excel to generate reports based on data within an Oracle 9 database. The amount of data is very large and the reports can take a long time to process. I have added status bar progress indicators for the majority of the report processing tasks to inform the user of what is going on.
    The problem is that I need to be able to monitor the progress of the main SQL queries since they take upwards of a few minutes to run each (mainly because I need to rank and order data). I currently use code similar to that shown below to query the database from VBA.
    Sub simpleVersion()
    Dim username As String
    Dim password As String
    Dim sid As String
    Dim objSession As Object
    Dim objdatabase As Object
    Dim OraDynaset As Object
    Dim strSQL As String
    username = "user"
    password = "pass"
    sid = "database"
    ' connect to database
    Set objSession = CreateObject("OracleInProcServer.XOraSession")
    Set objdatabase = objSession.OpenDatabase(sid, username & "/" & password, 0&)
    strSQL = "select latitude, longitude, otherdata from scatter where otherdata > 50 order by latitude, longitude"
    ' This command takes a long time to execute when doing ranks/order bys
    Set OraDynaset = objdatabase.DBCreateDynaset(strSQL, 0&)
    Do While OraDynaset.EOF = False
    'Process the data and put on a spreadsheet
    'Status bar messages can be used here without problems
    OraDynaset.MoveNext
    Loop
    Set OraDynaset = Nothing
    Set objSession = Nothing
    objdatabase.Close
    Set objdatabase = Nothing
    End Sub
    When the DBCreateDynaset command is executed VBA waits until the dynaset data is retrieved from oracle. I would like to be able to do something similar to the pseudo code below.
    Execute SQL to create dynaset
    Do while still obtaining dynaset
    Check v$session_longops - Indicate time taken / remaining on status bar
    Loop
    I have found that if you execute a large query without any tasks that require the whole dataset before they can begin (ranks, ordering etc) the dynaset is created almost instantly and excel does not freeze up.
    With non dynaset operations such as inserts it is possible to run the query in non blocking mode. I am able to monitor the progress of the query and indicate it to the user.
    Dim myStatement As OraSqlStmt
    Set myStatement = objdatabase.CreateSql(strSQL, ORASQL_NONBLK)
    Do While myStatement.NonBlockingState = ORASQL_STILL_EXECUTING
    DoEvents
    Select Case intSpinCount
    Case 1
    Application.StatusBar = "Please Wait. Calculating data /"
    Case 2
    Application.StatusBar = "Please Wait. Calculating data -"
    Case 3
    Application.StatusBar = "Please Wait. Calculating data \"
    Case 4
    Application.StatusBar = "Please Wait. Calculating data |"
    intSpinCount = 0
    End Select
    Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
    intSpinCount = intSpinCount + 1
    Loop
    Non blocking mode is explained here. However dynasets are not supported.
    http://download-west.oracle.com/docs/cd/A91202_01/901_doc/win.901/a90173/o4o00022.htm
    I have tried using pl/sql to insert the data requested into a temporary table and then the normal select statement to get the data back out. However since the data stored in a table is not ordered it isn’t much help to me since I still have to do the order by command.
    Anyone got any ideas?
    All help is much appreciated.

    Dear taktang
    I'm a newbie. I'd be grateful if you would tell me where to find "oracle-base"
    thanks
    mik3

  • Performing sql queries in java without using java libraries

    i wonder whether its possible to perform sql queries beginning from create table to updating queries without using the java sql library.
    has anyone written such code.

    You could use JNI to talk to a native driver like the Oracle OCI driver. Doing this is either exiting or asking for trouble depending on your attitude to lots of low level bugs.

  • PL/SQL Queries in OC

    Is it possible to write normal SQL Queries into the Custom Code of OC?
    for ex -
    "select count(a.visdate) from tablename" or
    "select max(col) from table name"?
    is it also possible to write and set up CURSORS in OC like how we do normally in PLSQL of oracle.

    Hi, Sorry for the late response, hope this helps.
    You would need do the following.
    "Declaration"- Create a cursor
    "Pre-Details" - Use cursor
    "Post-QG-A" Can specify the Qualifying Value here.
    After doing the hard work, you can than use the cursor variables in the validation procedure.
    Thanks,
    Naveen

  • Maintaining SQL Queries in a separate text file

    Hi,
    I am working on web based project using Spring MVC framework and I am maintaining all SQL queries in a separate text file so that I can change them any time when needed. I just want to know am I doing right, it this a optmistict way of coding??

    >
    I am working on web based project using Spring MVC framework and I am maintaining all SQL queries in a separate text file so that I can change them any time when needed. I just want to know am I doing right, it this a optmistict way of coding??
    >
    The best place to store the queries, and HOW to store them depends on your architecture and on how your application is being used.
    Is this a single-user application on a user's pc? Or is your application located on an application server in the middle-tier?
    The queries should be stored where they will be used. Your queries should be stored in the tier where your application code will reside. On the client PC for a single-user app, on the application server for a 3-tier app and incorporated into stored procedures/functions/packages if part of a database app.
    If your application is totally external to the database (e.g. a reporting app) then it doesn't make sense for you to become part of the database architecture. An org isn't going to let you create objects in the database to store your queries when your queries are not part of the database application. That puts the burden on them to backup your objects, restore them for your and provide support to you and your application.
    What format to store the queries in is a different issue. A major criteria is the type of queries you are using and how they are used. Many apps that query the database cannot just use hard-coded queries that are never modified. Users need to be able to provide parameters (e.g. name, ID, state, etc) to select just the data that they want.
    That means the base query itself may not even be valid syntax but needs to have a WHERE clause added. Prepared statements and queries that use bind variables ('WHERE ID = ?') are typically used for these.
    One method of storage is to use Java property files that use name=value pairs. Using property files makes it easy to use Java to find a query by name and load it for you. Then your code would have functionality to modify the query to provide the parameter 'bind' values and execute it.
    There are also frameworks available for handling database related functionality. There is no need for you to write your own libraries for this. I suggest you locate a suitable framework to use.

  • SQL Queries in BO

    Hi,
    I'm working with Business Objects 3.1 Desktop and Webi. I want to type SQL Queries but I don't know how to do it. Is it possible to create queries in BO Desktop and Webi? If so, how can I do it? I'm not Administrator, I'm only a user.
    Thanks in advance.

    Hi,
    Yes you can do by deski report.Create new report by based on Free hand SQL editor,create a connection for a database then paste sql in the editor and run.For more help login on the deski and go to the help tab and in the help you can find how to create report based on the Free hand SQL Editor.
    In webi you can achieve this thing by to create one universe and insert derived table and paste the sql.Then create classes and objects and then create webi report based on the universe.You can not create webi report direct on the Free hand SQL.
    In both of cases you have to rights to create report on Free Hand SQL editor or create universe.
    Thanks,
    Amit

  • Logging sql queries without any changes in existing apps

    Hi!
    Is it possible to log all SQL queries send from application to database via JDBC without any (or really small) changes in code of existing applications?
    I'm new to JDBC so any suggestions/ideas/best practices are welcome ;)
    Best regards.
    Edited by: matthew_ on Mar 16, 2008 5:35 PM

    Is it possible to log all SQL queries send from application to database via JDBCFirst is an assumption that the driver does in fact sends SQL. It might send some other form.
    But excluding that and excluding that the driver explicitly sends it then you can create a proxy driver. You implement the driver to pass everything to the real driver. Along the way it collects the information.
    You will find that that is quite bit of work. However it impacts the actual code very little and requires nothing more than loading the driver and changing the connection string in the code where it is used.

  • Which SQL queries to count on OFO 9042 & Content Services 10120

    Dear experts,
    In customer context we urgently need to know which SQL queries to use :
    - to count on OFO 9.0.4.2 the number of workspaces
    - to count on OFO 9.0.4.2 the number of metadata elements (categories & attributes) attached to documents
    - to count on Content Services 10.1.2.0 the number of containers
    - to count on Content Services 10.1.2.0 the number of libraries
    - to count on Content Services 10.1.2.0 the number of folders
    - to count on Content Services 10.1.2.0 the number of groups
    - to count on Content Services 10.1.2.0 the number of categories
    - to count on Content Services 10.1.2.0 the number of attributes
    - to count on Content Services 10.1.2.0 the number of workspaces
    Thank a lot for your kind answer.
    Best regards.
    Jean-Francois

    Congrats to Shanky and Durval!
     SQL Server General and Database Engine Technical Guru - June 2014  
    Shanky
    SQL Server: What does Column Compressed Page Count Value Signify
    in DMV Sys.dm_db_index_physical_stats ?
    DB: "Interesting and detailed"
    DRC: "• This is a good article and provides details of each and every step and the output with explanation. Very well formed and great information. • We can modify the create table query with “DEFAULT VALUES". CREATE TABLE [dbo].[INDEXCOMPRESSION](
    [C1] [int] IDENTITY(1,1) NOT NULL, [C2] [char](50) NULL DEFAULT 'DEFAULT TEST DATA' ) ON [PRIMARY]"
    GO: "Very informative and well formed article as Said says.. Thanks for that great ressource. "
    Durval Ramos
    How to get row counts for all Tables
    GO: "As usual Durva has one of the best articles about SQL Server General and Database Engine articles! Thanks, buddy!" "
    Jinchun Chen: "Another great tip!"
    PT: "Nice tip" 
    Ed Price: "Good topic, formatting, and use of images. This would be far better if the examples didn't require the black bars in the images. So it would be better to scrub the data before taking the screenshots. Still a good article. Thank you!"
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

Maybe you are looking for