Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 97f889bef48a575ec4e4e0453dc88a07 > files > 2

php-pear-DBA_Relational-0.2.0-4mdv2010.0.noarch.rpm

These are example queries and their results as generated by test_relational.
See empSchema in the tests directory to view how these tables are constructed.

Output of test_relational:

Creating table: emp
Creating table: dept
Creating table: location
Creating table: deptloc
Creating table: account
Query:
$db->select("emp", "*")

SQL equivalent:
SELECT * FROM emp

Results:
  id     empname   job        manager   hiredate    salary   comm   deptno  
 ------ --------- ---------- --------- ----------- -------- ------ -------- 
  7369   Smith     clerk      7782      265266000   800      0      20      
  7499   Allen     salesman   7782      351496800   1600     300    30      
  7521   Ward      salesman   7782      351669600   1250     500    30      
  7782   Clark     manager    7788      360910800   2450     0      10      
  7788   Scott     analyst    0         408261600   3000     0      20      

************************************************

Query:
$db->select("deptloc", "*")

SQL equivalent:
SELECT * FROM deptloc

Results:
  deptno   locno  
 -------- ------- 
  10       1      
  20       2      
  30       3      
  40       3      
  10       2      

************************************************

Query:
$db->select("location", "*")

SQL equivalent:
SELECT * FROM location

Results:
  locno   locname   
 ------- ---------- 
  1       New York  
  2       Austin    
  3       Chicago   

************************************************

Query:
$db->select("dept", "*")

SQL equivalent:
SELECT * FROM dept

Results:
  deptno   deptname     manager  
 -------- ------------ --------- 
  10       ACCOUNTING   7782     
  20       RESEARCH     7788     
  30       SALES        7369     
  40       OPERATIONS   7782     

************************************************

Query:
$db->select("account", "*")

SQL equivalent:
SELECT * FROM account

Results:
  id   rid   name    notes                    active  
 ---- ----- ------- ------------------------ -------- 
  0    100   Ford    Wear black to meetings   1       
  1    99    Chevy   Springtime casual                

************************************************

Query:
$db->select("nothere", "pigs == 'fly'")

SQL equivalent:
SELECT * FROM nothere WHERE pigs = "fly"

 Query failed.
DBA: table 'nothere' does not exist

************************************************

Query:
$db->select("emp", "salary >= 1500")

SQL equivalent:
SELECT * FROM emp
WHERE salary >= 1500

Results:
  id     empname   job        manager   hiredate    salary   comm   deptno  
 ------ --------- ---------- --------- ----------- -------- ------ -------- 
  7499   Allen     salesman   7782      351496800   1600     300    30      
  7782   Clark     manager    7788      360910800   2450     0      10      
  7788   Scott     analyst    0         408261600   3000     0      20      

************************************************

Query:
$db->sort("empname", "a",
    $db->select("emp", "(job != 'analyst') and (job != 'intern')")
    )

SQL equivalent:
SELECT * from emp
WHERE (job <> "analyst") AND (job <> "intern")
ORDER BY empname

Results:
  id     empname   job        manager   hiredate    salary   comm   deptno  
 ------ --------- ---------- --------- ----------- -------- ------ -------- 
  7499   Allen     salesman   7782      351496800   1600     300    30      
  7782   Clark     manager    7788      360910800   2450     0      10      
  7369   Smith     clerk      7782      265266000   800      0      20      
  7521   Ward      salesman   7782      351669600   1250     500    30      

************************************************

Query:
$db->sort("empname", "d",
    $db->select("emp", "(job != 'analyst') and (job != 'intern')")
    )

SQL equivalent:
SELECT * from emp
WHERE (job <> "analyst") AND (job <> "intern")
ORDER BY empname DESC

Results:
  id     empname   job        manager   hiredate    salary   comm   deptno  
 ------ --------- ---------- --------- ----------- -------- ------ -------- 
  7521   Ward      salesman   7782      351669600   1250     500    30      
  7369   Smith     clerk      7782      265266000   800      0      20      
  7782   Clark     manager    7788      360910800   2450     0      10      
  7499   Allen     salesman   7782      351496800   1600     300    30      

************************************************

Query:
$db->project("empname, deptname, deptno",
    $db->join("emp", "dept", "emp.deptno == dept.deptno")
    )

SQL equivalent:
SELECT empname, deptname, deptno FROM emp, dept
WHERE emp.deptno = dept.deptno

Results:
  empname   deptname     deptno  
 --------- ------------ -------- 
  Smith     RESEARCH     20      
  Allen     SALES        30      
  Ward      SALES        30      
  Clark     ACCOUNTING   10      
  Scott     RESEARCH     20      

************************************************

Query:
$db->join("location", 
    $db->join("dept", "deptloc", "dept.deptno == deptloc.deptno"),
        "location.locno == B.locno"
    )

SQL equivalent:
SELECT * FROM location, dept, deptloc
WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno

Results:
  locno   locname    deptno   deptname     manager  
 ------- ---------- -------- ------------ --------- 
  1       New York   10       ACCOUNTING   7782     
  2       Austin     10       ACCOUNTING   7782     
  2       Austin     20       RESEARCH     7788     
  3       Chicago    30       SALES        7369     
  3       Chicago    40       OPERATIONS   7782     

************************************************

Query:
$db->sort("manager", "a",
    $db->join("location",
        $db->join("dept", "deptloc", "dept.deptno == deptloc.deptno"),
            "location.locno == B.locno"
        )
    )

SQL equivalent:
SELECT * FROM location, dept, deptloc
WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno
ORDER BY manager

Results:
  locno   locname    deptno   deptname     manager  
 ------- ---------- -------- ------------ --------- 
  3       Chicago    30       SALES        7369     
  1       New York   10       ACCOUNTING   7782     
  2       Austin     10       ACCOUNTING   7782     
  3       Chicago    40       OPERATIONS   7782     
  2       Austin     20       RESEARCH     7788     

************************************************

Query:
$db->sort("empname, locname, deptname", "a",
    $db->project("empname, locname, deptname",
        $db->join("emp", 
            $db->join("location",
                $db->join("dept", "deptloc", "dept.deptno == deptloc.deptno"),
                    "location.locno == B.locno"
                ),
                "emp.id != B.manager"
            )
        )
    )

SQL equivalent:
SELECT empname, locname, deptname FROM location, dept, deptloc, emp
WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno
AND emp.id <> dept.manager
ORDER BY empname, locname, deptname

Results:
  empname   locname    deptname    
 --------- ---------- ------------ 
  Allen     Austin     ACCOUNTING  
  Allen     Austin     RESEARCH    
  Allen     Chicago    OPERATIONS  
  Allen     Chicago    SALES       
  Allen     New York   ACCOUNTING  
  Clark     Austin     RESEARCH    
  Clark     Chicago    SALES       
  Scott     Austin     ACCOUNTING  
  Scott     Chicago    OPERATIONS  
  Scott     Chicago    SALES       
  Scott     New York   ACCOUNTING  
  Smith     Austin     ACCOUNTING  
  Smith     Austin     RESEARCH    
  Smith     Chicago    OPERATIONS  
  Smith     New York   ACCOUNTING  
  Ward      Austin     ACCOUNTING  
  Ward      Austin     RESEARCH    
  Ward      Chicago    OPERATIONS  
  Ward      Chicago    SALES       
  Ward      New York   ACCOUNTING  

************************************************