How do I avoid an error (or replace the error with a meaningful comment) when selecting from a table that does not exist?
I have two boxes on a webpage. The user specifies a table-name in the first, I run a query based on that table-name and use the results of that query to populate the second [dropdown] box (using javascript).
All works well until the user specifies a table which does not exist. The query fails and the [dropdown] box is populated with an 'ugly' error. I would prefer it to be populated with 'Table does not exist'.
Because the function [php] code is used for many purposes it cannot be amended and I can only run 'simple' queries in it. I cannot use a stored procedure.
I have tried many ways to create this effect without success. To illustrate, I am looking for something with the following logic:-
SELECT IF
(SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_NAME = 'table_xxxxx') = 0
THEN 'Table Not Found'
ELSE
(SELECT id, name FROM table_xxxxx WHERE condition blah blah)
END
where table_xxxxx is specified by the user and substituted out
Thanks
May be you can use try ... catch block to eliminate 'ugly' error and show 'good' (or 'bad') error.
Related
I would like to find a way of writing a SELECT statement which includes using the column name as a search criteria in a data_glossary table.
Example SQL statement
SELECT field1, field2, field3
FROM table1
I want to include field_definition from a table called tbl_data_glossary using WHERE data_reference = 'field1' whenever I run a script. So I should get two data sets, the first one has the data, the second has what the data set values mean.
I hope that makes sense, I want to implement this in a way where a BI tool could not only pull values but include the information required to provide help for business users.
I have tagged this as SQL and Javascript but maybe you have a better way of approaching this.
I wonder if I need to setup my select statement using an array of variables somehow and then also use the same array in a WHERE data_reference IN [array] type statement.
So, if one of the fields in my SELECT statement is reference_definition_name I want a sub query or separate query to look up that column name as a value which is held in the column called reference_code in tbl_reference_data
Here's the tbl_reference_data table which contains the data glossary with example data:
(reference_def_id,
reference_def_name,
reference_def_created,
reference_def_last_updated,
dataset_category,
dataset_type,
reference_code,
reference_name,
reference_description,
reference_status,
reference_lang)
Example data:
('8f603ffe-6800-11ea-bc55-0242ac130003', 'Data Origin Identifiers', '17/03/2020 16:34', '17/03/2020 16:34', 'Reporting', 'data-glossary', 'reference_definition_name', 'Definition Name', 'This is the name of the reference data set related to the purpose of the reference definitions.','ACTIVE','EN')
Thanks, Matt
So my scenario is:
I have 2 tables on a screen, table 1 has certain data in it.
I want to assert that in each table the correct column & row headings exist.
So far what I have tried is: -
.expect(page.Table.nth(0).page.tableHeaderRow.nth(1).withText('row heading').exists).ok()
However when I try this I get the following 2 errors: -
1) A call to an async function is not awaited. Use the "await" keyword before actions, assertions or chains of
them to ensure that they run in the right sequence.
2) TypeError: Cannot read property 'tableHeaderRow' of undefined
I get that the above code I've written may be totally incorrect but how would I go about finding the row/column header in table 1 only?
As Marion mentioned, make sure that you added the "await" keyword. In addition, you can use specific TestCafe Selectors to find the required element (e.g. the ID, class or DOM Selector based on your markup) as described in the Selectors topic.
I have a tablesorter, with 2 filter Columns. The first Filter works as a drop down and has no issues right now. The second filter is intended to be a full table search and filter mechanism.
That is to say, even though it is associated with the computer column, it should return results for child rows as well
The Computer Filter should respond to all child rows. For instance, if I searched for z840, , only Computers with Model z840 should appear.
However, I have a custom secondary filter mechanism by request The gauge at the top, works as a filter for workgroup
However, If I am filtered in a workgroup, and use the Computer Filter, it ignores the custom hidden rows, and searches against any row in the table. (Child Row Searching works fine).
My Question is, Is there a way to overwrite the functionality of the filter, to ignore any rows that are already satisfying some condition IE: $(row).hasClass('hide')
I have tried using filter_functions but every result ends up searching on computer name only
I am using Jinja Templating so it was a little hard to get a fiddle up and running but here is a sample.
http://jsfiddle.net/brianz820/856bzzeL/813/
Sort by wg02 (at top, no results), and then use the computer filter to search for say, 3.3. No results show up, but once you delete the search, the original workgroup filter is removed.
On my production copy, even typing 3.3 would have returned results for any workgroup, ignoring the filter.
There may be lots of extraneous code on Fiddle, just wanted to get a working version up
Thanks for reading, Goal to maintain free form child searching and filtering on filter selection, but maintain external hidden rows.
if there is any more required information please let me know
I'm not exactly sure if this is what you meant, but the hideRows function can be simplified by using the filter widget (demo):
function hideRows() {
var $table = $('.tablesorter'),
filters = $.tablesorter.getFilters( $table );
filters[2] = selected === 'All' ? '' : selected;
$.tablesorter.setFilters( $table, filters );
}
Using TestComplete's javascript engine to create a TADOConnection to a remote Oracle 11.2.0.3 server.
The query is a simple select with some basic where clauses:
Select * FROM MyUser.MyTable WHERE MyName = 'NAME' AND MyId like '1111%'
When executing the command, it fails and hits an exception with the helpful message of "Unspecified Error"
The odd part to this: Several other selects, deletes, inserts... work just fine using all the same connection logic. The same query even works if I change the * to the column names instead:
Select MyCol1, MyCol2, MyCol3 FROM MyUser.MyTable WHERE MyName = 'NAME' AND MyId like '1111%'
While this is a workaround, the tables have a very large number of Columns and I'd like the * to work as intended. Any ideas what may be causing the query to fail?
Also, running the query from sqlcmd and sqldeveloper both behave and return proper results.
This means that the table contains one or more fields with data type which is not supported by the OLE DB provider you use. To find out which exactly fields are problematic, you can add fields one by one to the query and check whether it works. Once you found the problematic fields, you will have to list all fields except for these in your Select clause.
Also, if you are using a provider from Microsoft (provider=MSDAORA), try changing it to the Oracle native provider (provider=OraOLEDB.Oracle).
I have a page that has around 30 different entry fields, one of the top fields is a textfield and after this is filled in, I want to populate a dropdown and a textfield. I currently have it calling a javascript function, however my main problem is that I need to query the database to find out what value to populate the fields with.
Here is the type of thing I was trying to do:
function populateState(){
<cfquery name="getState" datasource="#application.dsn#">
SELECT STATE_CODE, CODE_ID
FROM LERG_LATA_V1 LEFT OUTER JOIN Code ON STATE_CODE = CHAR1_TX
WHERE NPX = #NPANXX#
</cfquery>
}
And then after that I would need to read the result and select that element. Any suggestions on how to do this? Most of what I am finding on my google searches are saying you cannot mix cf and js since they execute at different times.
You need to either create a state JavaScript array with your query, and then reference that in your javascript, or use the built-in cfselect tag binding to make this happen. Here's a simple example of how I do this:
http://www.dansshorts.com/post/cfselect-binding-and-selectedvalues
Dan