Testing for existence of a table - MySQL
I'm using MySQL and I just want to see if a table exists so
that I can either select data from it or if it does not exists, I
want to pull the same fields from a table that I already know
exists.
Any help would be greatly appreciated.
Thanks
quote:
Originally posted by:
BKBK
using MySQL
<cfquery name="tableExists" datasource="DSN">
SELECT count(*) as testValue
FROM information_schema.tables
WHERE table_schema = 'the_database_name'
AND table_name = 'your_table_name'
</cfquery>
<cfif tableExists.testValue[1] GT 0><!--- your table
exists --->
<cfquery name="q" datasource="DSN">
SELECT *
FROM your_table_name
</cfquery>
<cfelse><!--- your table doesn't exist --->
<cfquery name="q" datasource="DSN">
SELECT *
FROM other_table_name
</cfquery>
</cfif>
<cfdump var="#q#">
Thanks BKBK!. That works perfectly. I don't administer the
ColdFusion Server, so I'm hoping the administrators are handling
any security issues.
Similar Messages
-
How to test for existence of AcroXFA test objects?
Hi -
I'm writing scripts to test an XFA form with dynamic subforms. For example, at the end of Part 4, the user hits a Validate button, and if their data is correct, then the Validate button disappears and a Part 5 subform appears.
So my script looks something like this:
Function GetButtonPart4Validate()
Set GetButtonPart4Validate = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1")
.AcroXFAForm("sfPart4").AcroXFAButton("sfValidate")
End Function
Function GetPart5()
Set GetPart5 = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").AcroXFAForm("sfPart5")
End Function
GetButtonPart4Validate().Click
PDFDoc( "TestForm" ).WaitProperty "ready", true, 60000 ' Wait for event processing complete
If DataTable("boolValidates", dtLocalSheet) = "TRUE" Then
If( GetPart5().Exist ) Then
' A: Checkpoint Succeeds: Validation was successful
Else
' B: Checkpoint fails: Validation failed
Endif
Else
If( GetPart5().Exist ) Then
' C: Checkpoint Fails: Validation was unexpected
Else
' D: Checkpoint Succeeds: Validation failed as expected
Endif
Endif
Unfortunately it appears that XfaSubForm.Exist always returns TRUE. In other QTP testing domains (eg "Exist Property (WinObject)" in QTP Help), the documented behaviour of the Exist property is to be true if the desired test object can be found in the application-under-test. Typically this means that when the script tries to access an XFA widget which doesn't exist (even something like GetPart5().getROProperty("visible") ), the script stops and thinks for a minute or so, and eventually produces a test error that the object doesn't exist then muddles onward. It is the "stops and thinks for a minute or so" which frustrates me, since these are delays which I am trying to avoid.
Another possible angle I looked into was counting the subforms under Part 5's parent.
PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").RefreshObject
PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").AcroXFAForm("sfPart5").Refresh Object
' check to see if there is a 'sfPart5'
Dim MyChildren, i
Set MyChildren = PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("form1").ChildObjects
For i=0 to MyChildren.Count - 1
print i & " name=" & MyChildren(i).GetROProperty("name")
Next
This also seems to fail: Part5 doesn't appear among its parent's children (at least before QTP actually tries to use it).
The PDF Test Toolkit User Guide doesn't specifically mention that Exist or RefreshObject or ChildObjects are implemented, so I can't say AcroQTP isn't working as designed, but if you're looking for suggestions for improvement, I'll vote for fulfilling these parts to the QTP. Please confirm my conclusions that these are not properly implemented, or whether I'm missing something.
In the meantime, do you have any recommendation on how to proceed? My present workaround is to look for a "validation error" windows dialog that indicates Part 5 won't exist, but this won't work in future test scripts.
Cheers,
BrentHi,
816387 wrote:
... QUERY:- Find all customers who have at most one account at the Perryridge branch.
SOLUTION *1* :-
select customer_name
from depositor,account
where account.account_number=depositor.account_number and
branch_name='Perryridge'
group by customer_name
having count(account.account_number) <=1
ok running correctly
That finds customers who have exactly one account at Perryridge.
The assignment is to find customers who have at most one account at Perryridge. You need to include customers with 0 accounts at Perryridge, as well. You could use an outer join, or MINUS, or a NOT IN subquery, or a NOT EXISTS sub-query (as mentioned above) to do that.
Can there be customers who have no accounts at all, at any branch? If so, you'll need to use the customer table in this problem, as well as depositor and account.
>
SOLUTION *2* :-
select D1.customer_name
from depositor D1
where unique
(select customer_name
from depositor D2,account A1
where D1.customer_name=D2.customer_name
D2.account_number=A1.account_number and
branch_name='Perryridge'
gives error:-
where unique
..........*^*
ERROR at line 3:
ORA-00936: missing expression
Logic of both solution are correct . But Solution 2 gives error in oracle. I want unique construct to work.Sorry, it doesn't in Oracle. I don't know of anything like that in Oracle.
Does "WHERE UNIQUE (SELECT ...)" work in some other database system? Which?
How to do it. Or How can i test for the absence of duplicate tuples ??????
Your Solution 1 is the best way to find customers with exatly 1 account (rather than 0 or 1 accounts) at Perryridge. Is there any reason why you wouldn't want to use it, if you ever needed to find customers with exactly one account there? -
[solved] Best way to test for record in sqlite3 db?
In a bash script, I need to know if a sqlite3 'SELECT ... WHERE' operation finds any matches. I don't need the output; I just need to know if a match is found. My thought was to do
if [[ "$(sqlite3 ... "SELECT ..." )" ]];then ...
Is there a better way to do it?
Bonus question: if searching a primary key or unique column, is a ' SELECT ... WHERE foo="bar" ' operation smart enough to stop when it finds a match, or will it continue through the rest of the table?
Thanks.
Last edited by alphaniner (2012-04-26 14:51:36)@alphaniner: Primary key columns are usually indexed, hence a query for a primary key column will not traverse the table, but perform an index lookup. Since primary keys are unique this will end up at a single row.
To test for existence of a row, you'd usually use "select exists(select 1 from <table> where <condition>)". This will output 1, if the row exists, and 0 otherwise. I don't know whether the exit state of the "sqlite" tool is reliable, but testing the output will be with this query.
And again: If you're doing this kind of stuff, you're better off with a real languages with data types and the like. Python provides SQLite support in the standard library. -
Testing for IS NOT NULL with left join tables
Dear Experts,
The query is showing the NULL rows in the query below....
Any ideas, advice please? tx, sandra
This is the sql inspector:
SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE
, O100404.NAME, O100321.PERSON_UID, O100404.PERSON_UID, O100404.VISA_TYPE
FROM ODSMGR.PERSON O100321
, ODSMGR.VISA O100404
WHERE ( ( O100321.PERSON_UID = O100404.PERSON_UID(+) ) ) AND ( O100404.VISA_TYPE(+) IS NOT NULL )Hi Everyone,
I am understanding alot of what Michael and Rod wrote.... I am just puzzled over the following:
the query below is left joining the STUDENT table to
HOLD table.
The HOLD table - contains rows for students who have holds on their record.
a student can have more than one hold (health, HIPAA, basic life saving course)
BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
1 to many relationship.
Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
me having to code IS NOT NULL twice....
Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
the IS NOT NULL condition.
I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
and how they should create a query. I need to come up with rules.
If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
thx sooo much, Sandra
SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
ORDER BY O100384.NAME ASC -
Mainframe data loaded into Oracle tables - Test for low values using PL/SQL
Mainframe legacy data has been copied straight from the legacy tables into mirrored tables in Oracle. Some columns from the mainframe data had 'low values' in them. These columns were defined on the Oracle tables as varchar2 types. In looking at the data, some of these columns appear to have data that looks like little square boxes, not sure but maybe that is the way Oracle interprets the 'low values' in the original data into varchar. When I run a select to find all rows where this column is not null, it selects these columns. In the results of the select statement, the columns appear to be blank, however, in looking at the data in the column using SQL Developer, I can see the odd 'square boxes'. My guess is that the select statement is detecting that something exists in this column. Long story short, some how I am going to have to test this legacy data on the Oracle table using Pl/Sql to test for 'low values'. Does anyone have any suggestions on how I could do this????? Help! The mainframe data we are loading into these tables is loaded with columns with low values.
I am using Oracle 11i.
Thanks
Edited by: ncsthbell on Nov 2, 2009 8:38 AMncsthbell wrote:
Mainframe legacy data has been copied straight from the legacy tables into mirrored tables in Oracle. Not a wise thing to do. Mainframe operating systems typically use EBCDIC and Unix and Windows servers use ASCII. The endian is also different (big endian vs little endian).
Does anyone have any suggestions on how I could do this????? As suggested, use the SQL function called DUMP() to see the actual contents (in hex) of these columns. -
Sample report for filling the database table with test data .
Hi ,
Can anyone provide me sample report for filling the database table with test data ?
Thanks ,
Abhi.hi
the code
data : itab type table of Z6731_DEPTDETAIL,
wa type Z6731_DEPTDETAIL.
wa-DEPT_ID = 'z897hkjh'.
wa-DESCRIPTION = 'computer'.
append wa to itab.
wa-DEPT_ID = 'z897hkjhd'.
wa-DESCRIPTION = 'computer'.
append wa to itab.
loop at itab into wa.
insert z6731_DEPTDETAIL from wa.
endloop.
rewards if helpful -
Revision: 18814
Revision: 18814
Author: [email protected]
Date: 2010-11-24 09:31:56 -0800 (Wed, 24 Nov 2010)
Log Message:
Add manual test for BLZ-594 with instructions on how to run the test.
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-594
Modified Paths:
blazeds/trunk/qa/apps/qa-manual/WEB-INF/flex/remoting-config.mods.xml
Added Paths:
blazeds/trunk/qa/apps/qa-manual/WEB-INF/src/test/
blazeds/trunk/qa/apps/qa-manual/WEB-INF/src/test/RpcTest.java
blazeds/trunk/qa/apps/qa-manual/bugs/BLZ-594/
blazeds/trunk/qa/apps/qa-manual/bugs/BLZ-594/BLZ-594.mxml
blazeds/trunk/qa/apps/qa-manual/bugs/BLZ-594/readme.txtYou do have a very complex looking site and may need several tables in mysql to handle all that data. If you knew to phpmysql I would suggest taking a look at this tutorial it will help get you started in understanding how to $_GET info from a database and also how to $_POST data to a database. I am no expert just learning myself and I found this very helpful. This is the link http://www.adobe.com/devnet/dreamweaver/articles/first_dynamic_site_pt1.html
There are also many tutorials on Youtube to help build a CMS Content Management Site I would suggest the following: -
http://www.youtube.com/user/phpacademy
http://www.youtube.com/user/betterphp
http://www.youtube.com/user/flashbuilding
And many more on my channel here
http://www.youtube.com/user/Whisperingonthewind
CMS's are easier to maintain, add edit and delete content.
I have also recently bought a Book by David Powers Training from the Source very helpful.
Anyway hope you get it sorted. -
How to test for différent Select into a single PL/SQL block ?
Hi,
I am relatively new to PL/SQL and I am trying to do multiple selects int a single PL/SQL block. I am confronted to the fact that if a single select returns no data, I have to go to the WHEN DATA_NOT_FOUND exception.
Or, I would like to test for different selects.
In an authentification script, I am searching in a table for a USER ID (USERID) and an application ID, to check if a user is registered under this USERID for this APPLICATION.
There are different possibilities : 4 possibilities :
- USERID Existing or not Existing and
- Aplication ID found or not found for this particular USERID.
I would like to test for thes 4 possibilities to get the status of this partiular user regardin this application.
The problem is that if one select returns no row, I go to the exception data not found.
In the example below you see that if no row returned, go to the exception
DECLARE
P_USERID VARCHAR2(400) DEFAULT NULL;
P_APPLICATION_ID NUMBER DEFAULT NULL;
P_REGISTERED VARCHAR2(400) DEFAULT NULL;
BEGIN
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
:P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
EXCEPTION
WHEN NO_DATA_FOUND THEN
:P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
END;I would like to do first this statement :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID Then to do this one if the user is found :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;etc...
I basically don't want to go to the not found exception before having tested the 4 possibilities.
Do you have a suggestion ?
Thank you for your kind help !
ChristianSurely there are only 3 conditions to check?
1. The user exists and has that app
2. The user exists and doesn't have that app
3. The user doesn't exist
You could do this in one sql statement like:
with mimic_data_table as (select 1 userid, 1 appid from dual union all
select 1 userid, 2 appid from dual union all
select 2 userid, 1 appid from dual),
-- end of mimicking your table
params_table as (select :p_userid userid, :p_appid appid from dual)
select pt.userid,
pt.appid,
decode(min(case when dt.userid = pt.userid and dt.appid = pt.appid then 1
when dt.userid = pt.userid then 2
else 3
end), 1, 'User and app exist',
2, 'User exists but not for this app',
3, 'User doesn''t exist') user_app_check
from mimic_data_table dt,
params_table pt
where pt.userid = dt.userid (+)
group by pt.userid, pt.appid;
:p_userid = 1
:p_appid = 2
USERID APPID USER_APP_CHECK
1 2 User and app exist
:p_userid = 1
:p_appid = 3
USERID APPID USER_APP_CHECK
1 3 User exists but not for this app
:p_userid = 3
:p_appid = 2
USERID APPID USER_APP_CHECK
3 2 User doesn't exist -
hi Friends ,i need a suggestion from you on how to
insert data to all tables on a Database "A " on Test server
Select data from all tables on a Database "A" on Production Server
where id=123
Database A is same with Structures on Test and Production also all Tables will have Id column in common.
The purpose of this insert is ,as we all know Production has the latest data and i need to push to test server on request for particular ID only ( may be weekly once or twice a week )
I have a linked server setup name "LINQ"
Example for one table is below , like wise i need a script which does for 154 tables.
Insert into ABC( id, name)---insert to test server
Select Id, name from LINQ.ProdSerevrname.databasename.ABC where id = 123
Please help me ..
ThanksWhy not use export import wizard for this if you've read access to production?
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
SESSION VARIABLES : HOW TO TEST FOR MULTIPLE USERS
I have a username session variable set up on a localhost testing envirnoment.
This works fine for one user, but when I open another occurence of the browser (or just another tab) to test for multiple users the system overwrites the session variable with the last username input.
So the question is:
Why doesn't dreamweaver hold an instance of the session variable for each browser session? and if not what are your suggestions?
Thanks
Adam.Thanks for that.
After scouring the internet I found the only way of running 2 instances of firefox without them sharing the session variables is to create 2 new firefox profiles in windows + set the MOZ_NO_REMOTE environment variable.
Internet explorer is much easier as it has a 'new session' option in the file menu, but seems to have more trouble displaying tables correctly.
Hope this helps anyone with a similar problem. -
Where can i get sample tests for sun certification(programmer level)??
where can i get sample tests for sun certification(programmer level)??
advanced thanks
anuHi,
Check this link.
www.javaranch.com/maha
Goto the Mock Exams section. There is a table with links to free and paid Mock exams
on net. They are also rated for being close to the real exams and helping you learn.
Even the resources here is very good. They are also rated by users.
This is one of the best sites I have visited to prepare for the SJCP exam.
Hope this info helps.
Regards,
Roopasri Vittal
Developer Technical Support
Sun Microsystems
http://sun.com/developers/support -
In the current version (2.1.0.63) I can perform only unit test for packages, function and procedures. But we use a lot of object types in the database and would like to test them. Is there any support for object types scheduled?
You can also use the original UT PLSQL package from sourceforge.
I have used this in the past for testing with file comparisons, table object output from procedures, etc.
We've also used the same setup for Oracle Forms code testing.
Dennis -
JPA: How to initialise an entity for a self-referencing table?
I am working on a project that requires a self-referencing table:
mysql> show create table attributes\G
*************************** 1. row ***************************
Table: attributes
Create Table: CREATE TABLE `attributes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent` int(11) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`name` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent` (`parent`),
KEY `type` (`type`),
CONSTRAINT `attributes_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `attributes` (`id`),
CONSTRAINT `attributes_ibfk_2` FOREIGN KEY (`type`) REFERENCES `attributes` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1
I used NetBeans to generate an entity class from the table:
@Entity
@Table(name = "attributes")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Attributes.findAll", query = "SELECT a FROM Attributes a"),
@NamedQuery(name = "Attributes.findById", query = "SELECT a FROM Attributes a WHERE a.id = :id"),
@NamedQuery(name = "Attributes.findByName", query = "SELECT a FROM Attributes a WHERE a.name = :name")})
public class Attributes implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Size(max = 128)
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "parent")
private Collection<Attributes> attributesCollection;
@JoinColumn(name = "parent", referencedColumnName = "id")
@ManyToOne
private Attributes parent;
@OneToMany(mappedBy = "type")
private Collection<Attributes> attributesCollection1;
@JoinColumn(name = "type", referencedColumnName = "id")
@ManyToOne
private Attributes type;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "attributes")
private Collection<ItemAttributes> itemAttributesCollection;
@OneToMany(mappedBy = "ivalue")
private Collection<ItemAttributes> itemAttributesCollection1;
But how can I write a constructor for this entity? The auto-generated code gets around the issue by doing nothing; the constructor is empty. I can't help thinking that if I set the parent and type references to anything with new Attributes(), then it will recurse out of control. What else can/shall I do? I know how to rewrite it to not use the entity relations, but I'd prefer to make it work.Cymae wrote:
I don't want to call the hash table creation method because from what i understand about interfaces the idea is that your main method doesnt know the table is actually a hash table...is that right?That's not exactly the idea. The idea to use the interface as the type instead of the implementation, is that your class probably doesn't need to know the full type. This makes it easy to change the implementation of the interface if needed. However, somebody at some point has to create the concrete object, a HashTable.
Basically, an interface describes a behavior, and a class that implements an interface decides how to actually perform this behavior. It is obviously impossible to perform the behavior if you are not told how to perform it.
Table table = new HashTable() is the correct way to do it. This means that if you ever need you Table implementation to change, the only thing you need to change in your whole class is this line. For example you might want Table table = new FileTable(). -
OpenScript: How do you test for object/text existance programmatically?
Hi, All;
I hope someone can help me; kind of new to OATS. I can’t figure out how to test for object/text existence and return results back to the script. There are methods for verifying text and objects; i.e.
Web.verifyText
Web.assertText
These methods just report pass or fail to the test. I need to get the data back programmatically so I can use it logically. I know you can do this pretty easily in Selenium and QTP so there must be a way in OATS.
Thanks,
EricHi Eric,
You can use the Object Explorer to find the xpath of the object you are interested and check for its existence, and then grab some attribute of that object for use elsewhere.
if (web.element(6,"/web:window[@index='0' or @title='Software and Services - SCL']/web:document[@index='0']/web:span[@text='Services' or @index='14']")
.exists()){
System.out.println("OBJECT EXISTS");
// get an attribute of object here ,e.g
String myval = web.element(41,"/web:window[@index='0' or @title='Software and Services - SCL']/web:document[@index='0']/web::span[@text='Services' or @index='14'].getAttribute("innerText");
// use myval elsewhere
Hope it helps.
Jamie -
Read files starting with TEST* (for example)
Hi all,
Is it possible to read all the files starting with TEST for example from the Unix folder.
Requirement is there will be files starting with TEST present in the default path x.
I need to read all the files starting with TEST from this path. So, basically in the selection screen, can I put the default filename as TEST*.
All these files will have POs(Purchase Orders) which the program needs to update accordingly.
Please assist.
Thanks and regards,
AnishurHi,
I had to do the same. Selecting all values from table comparing konzs that start with number 500* .
check the code:
lv_var = '500'.
CONCATENATE lv_var '%' INTO h_concern.
SELECT * INTO TABLE t_lfa1
FROM lfa1
WHERE konzs LIKE h_concern.
Adibo.
Maybe you are looking for
-
I know the older macbook and macbook pro had a video out but I am not seeing any.
-
Is this a bug of Java? Or my mind?
Thank you all of you! I wrote a Filter like this: public class FilterDispatcherExample implements Filter{ public void doFilter(ServletRequest request,ServletResponse response, FilterChain chain) throws java.io.IOException,ServletException{
-
Standard report-Position(urgent)
Hi Is there any standard report where we can kown an employee assigned to two different Positions. or Position is assigned to two or more employees. Thanks Archana
-
Are there any plans for following features: 1: Be able to customize color themes 2: Be able to have more scaling options in Charts 3: Flatten maps, maps not showing contours.. 4; Improved KPI viewing, in ecample be able to create scorecard like those
-
I'm trying to find my iPad but I'm traveling and don't have the serial number. I cannot figure out how to use my iPhone to locate it. Can anyone assist?