| 
 | 1 | +*** Settings ***  | 
 | 2 | +Library           DatabaseLibrary  | 
 | 3 | +Library           OperatingSystem  | 
 | 4 | + | 
 | 5 | +*** Variables ***  | 
 | 6 | +${DBName}         my_db_test  | 
 | 7 | + | 
 | 8 | +*** Test Cases ***  | 
 | 9 | +Remove old DB if exists  | 
 | 10 | +    Comment    ${Status}    ${value} =    Run Keyword And Ignore Error    File Should Not Exist    /Users/jerry/Desktop/TestCases/TestSQLite3.db  | 
 | 11 | +    ${Status}    ${value} =    Run Keyword And Ignore Error    File Should Not Exist    ./${DBName}.db  | 
 | 12 | +    Comment    Run Keyword If    "${Status}" == "FAIL"    Run Keyword And Ignore Error    Run    rm -rf $HOME/Desktop/TestCases/TestSQLite3.db  | 
 | 13 | +    Run Keyword If    "${Status}" == "FAIL"    Run Keyword And Ignore Error    Run    rm -rf ./${DBName}.db  | 
 | 14 | +    Comment    File Should Not Exist    /Users/jerry/Desktop/TestCases/TestSQLite3.db  | 
 | 15 | +    File Should Not Exist    ./${DBName}.db  | 
 | 16 | +    Comment    Sleep    1s  | 
 | 17 | + | 
 | 18 | +Connect to SQLiteDB  | 
 | 19 | +    Comment    Connect To Database Using Custom Params sqlite3 database='path_to_dbfile\dbname.db'  | 
 | 20 | +    Connect To Database Using Custom Params    sqlite3    database="./${DBName}.db"  | 
 | 21 | + | 
 | 22 | +Create person table  | 
 | 23 | +    ${output} =    Execute SQL String    CREATE TABLE person (id integer unique,first_name varchar,last_name varchar);  | 
 | 24 | +    Log    ${output}  | 
 | 25 | +    Should Be Equal As Strings    ${output}    None  | 
 | 26 | + | 
 | 27 | +Execute SQL Script - Insert Data person table  | 
 | 28 | +    ${output} =    Execute SQL Script    ./${DBName}_insertData.sql  | 
 | 29 | +    Log    ${output}  | 
 | 30 | +    Should Be Equal As Strings    ${output}    None  | 
 | 31 | + | 
 | 32 | +Execute SQL String - Create Table  | 
 | 33 | +    ${output} =    Execute SQL String    create table foobar (id integer primary key, firstname varchar unique)  | 
 | 34 | +    Log    ${output}  | 
 | 35 | +    Should Be Equal As Strings    ${output}    None  | 
 | 36 | + | 
 | 37 | +Check If Exists In DB - Franz Allan  | 
 | 38 | +    Check If Exists In Database    SELECT id FROM person WHERE first_name = 'Franz Allan';  | 
 | 39 | + | 
 | 40 | +Check If Not Exists In DB - Joe  | 
 | 41 | +    Check If Not Exists In Database    SELECT id FROM person WHERE first_name = 'Joe';  | 
 | 42 | + | 
 | 43 | +Table Must Exist - person  | 
 | 44 | +    Table Must Exist    person  | 
 | 45 | + | 
 | 46 | +Verify Row Count is 0  | 
 | 47 | +    Row Count is 0    SELECT * FROM person WHERE first_name = 'NotHere';  | 
 | 48 | + | 
 | 49 | +Verify Row Count is Equal to X  | 
 | 50 | +    Row Count is Equal to X    SELECT id FROM person;    2  | 
 | 51 | + | 
 | 52 | +Verify Row Count is Less Than X  | 
 | 53 | +    Row Count is Less Than X    SELECT id FROM person;    3  | 
 | 54 | + | 
 | 55 | +Verify Row Count is Greater Than X  | 
 | 56 | +    Row Count is Greater Than X    SELECT * FROM person;    1  | 
 | 57 | + | 
 | 58 | +Retrieve Row Count  | 
 | 59 | +    ${output} =    Row Count    SELECT id FROM person;  | 
 | 60 | +    Log    ${output}  | 
 | 61 | +    Should Be Equal As Strings    ${output}    2  | 
 | 62 | + | 
 | 63 | +Retrieve records from person table  | 
 | 64 | +    ${output} =    Execute SQL String    SELECT * FROM person;  | 
 | 65 | +    Log    ${output}  | 
 | 66 | +    Should Be Equal As Strings    ${output}    None  | 
 | 67 | + | 
 | 68 | +Verify person Description  | 
 | 69 | +    [Tags]    db    smoke  | 
 | 70 | +    Comment    Query db for table column descriptions  | 
 | 71 | +    @{queryResults} =    Description    SELECT * FROM person LIMIT 1;  | 
 | 72 | +    Log Many    @{queryResults}  | 
 | 73 | +    ${output} =    Set Variable    ${queryResults[0]}  | 
 | 74 | +    Should Be Equal As Strings    ${output}    ('id', None, None, None, None, None, None)  | 
 | 75 | +    ${output} =    Set Variable    ${queryResults[1]}  | 
 | 76 | +    Should Be Equal As Strings    ${output}    ('first_name', None, None, None, None, None, None)  | 
 | 77 | +    ${output} =    Set Variable    ${queryResults[2]}  | 
 | 78 | +    Should Be Equal As Strings    ${output}    ('last_name', None, None, None, None, None, None)  | 
 | 79 | +    ${NumColumns} =    Get Length    ${queryResults}  | 
 | 80 | +    Should Be Equal As Integers    ${NumColumns}    3  | 
 | 81 | + | 
 | 82 | +Verify foobar Description  | 
 | 83 | +    [Tags]    db    smoke  | 
 | 84 | +    Comment    Query db for table column descriptions  | 
 | 85 | +    @{queryResults} =    Description    SELECT * FROM foobar LIMIT 1;  | 
 | 86 | +    Log Many    @{queryResults}  | 
 | 87 | +    ${output} =    Set Variable    ${queryResults[0]}  | 
 | 88 | +    Should Be Equal As Strings    ${output}    ('id', None, None, None, None, None, None)  | 
 | 89 | +    ${output} =    Set Variable    ${queryResults[1]}  | 
 | 90 | +    Should Be Equal As Strings    ${output}    ('firstname', None, None, None, None, None, None)  | 
 | 91 | +    ${NumColumns} =    Get Length    ${queryResults}  | 
 | 92 | +    Should Be Equal As Integers    ${NumColumns}    2  | 
 | 93 | + | 
 | 94 | +Verify Query - Row Count person table  | 
 | 95 | +    ${output} =    Query    SELECT COUNT(*) FROM person;  | 
 | 96 | +    Log    ${output}  | 
 | 97 | +    Should Be Equal As Strings    ${output}    [(2,)]  | 
 | 98 | + | 
 | 99 | +Verify Query - Row Count foobar table  | 
 | 100 | +    ${output} =    Query    SELECT COUNT(*) FROM foobar;  | 
 | 101 | +    Log    ${output}  | 
 | 102 | +    Should Be Equal As Strings    ${output}    [(0,)]  | 
 | 103 | + | 
 | 104 | +Verify Execute SQL String - Row Count person table  | 
 | 105 | +    ${output} =    Execute SQL String    SELECT COUNT(*) FROM person;  | 
 | 106 | +    Log    ${output}  | 
 | 107 | +    Should Be Equal As Strings    ${output}    None  | 
 | 108 | + | 
 | 109 | +Verify Execute SQL String - Row Count foobar table  | 
 | 110 | +    ${output} =    Execute SQL String    SELECT COUNT(*) FROM foobar;  | 
 | 111 | +    Log    ${output}  | 
 | 112 | +    Should Be Equal As Strings    ${output}    None  | 
 | 113 | + | 
 | 114 | +Insert Data Into Table foobar  | 
 | 115 | +    ${output} =    Execute SQL String    INSERT INTO foobar VALUES(1,'Jerry');  | 
 | 116 | +    Log    ${output}  | 
 | 117 | +    Should Be Equal As Strings    ${output}    None  | 
 | 118 | + | 
 | 119 | +Verify Query - Row Count foobar table 1 row  | 
 | 120 | +    ${output} =    Query    SELECT COUNT(*) FROM foobar;  | 
 | 121 | +    Log    ${output}  | 
 | 122 | +    Should Be Equal As Strings    ${output}    [(1,)]  | 
 | 123 | + | 
 | 124 | +Verify Delete All Rows From Table - foobar  | 
 | 125 | +    Delete All Rows From Table    foobar  | 
 | 126 | +    Comment    Sleep    2s  | 
 | 127 | + | 
 | 128 | +Verify Query - Row Count foobar table 0 row  | 
 | 129 | +    Row Count Is 0    SELECT * FROM foobar;  | 
 | 130 | +    Comment    ${output} =    Query    SELECT COUNT(*) FROM foobar;  | 
 | 131 | +    Comment    Log    ${output}  | 
 | 132 | +    Comment    Should Be Equal As Strings    ${output}    [(0,)]  | 
0 commit comments