modernc.org/cc@v1.0.1/v2/testdata/_sqlite/test/quote.test (about)

     1  # 2001 September 15
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  # This file implements regression tests for SQLite library.  The
    12  # focus of this file is the ability to specify table and column names
    13  # as quoted strings.
    14  #
    15  # $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $
    16  
    17  set testdir [file dirname $argv0]
    18  source $testdir/tester.tcl
    19  
    20  # Create a table with a strange name and with strange column names.
    21  #
    22  do_test quote-1.0 {
    23    catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
    24  } {0 {}}
    25  
    26  # Insert, update and query the table.
    27  #
    28  do_test quote-1.1 {
    29    catchsql {INSERT INTO '@abc' VALUES(5,'hello')}
    30  } {0 {}}
    31  do_test quote-1.2.1 {
    32    catchsql {SELECT * FROM '@abc'}
    33  } {0 {5 hello}}
    34  do_test quote-1.2.2 {
    35    catchsql {SELECT * FROM [@abc]}  ;# SqlServer compatibility
    36  } {0 {5 hello}}
    37  do_test quote-1.2.3 {
    38    catchsql {SELECT * FROM `@abc`}  ;# MySQL compatibility
    39  } {0 {5 hello}}
    40  do_test quote-1.3 {
    41    catchsql {
    42      SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'
    43    }
    44  } {0 {hello 10}}
    45  do_test quote-1.3.1 {
    46    catchsql {
    47      SELECT '!pqr', '#xyz'+5 FROM '@abc'
    48    }
    49  } {0 {!pqr 5}}
    50  do_test quote-1.3.2 {
    51    catchsql {
    52      SELECT "!pqr", "#xyz"+5 FROM '@abc'
    53    }
    54  } {0 {hello 10}}
    55  do_test quote-1.3.3 {
    56    catchsql {
    57      SELECT [!pqr], `#xyz`+5 FROM '@abc'
    58    }
    59  } {0 {hello 10}}
    60  do_test quote-1.3.4 {
    61    set r [catch {
    62      execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
    63    } msg ]
    64    lappend r $msg
    65  } {0 {hello 10}}
    66  do_test quote-1.4 {
    67    set r [catch {
    68      execsql {UPDATE '@abc' SET '#xyz'=11}
    69    } msg ]
    70    lappend r $msg
    71  } {0 {}}
    72  do_test quote-1.5 {
    73    set r [catch {
    74      execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
    75    } msg ]
    76    lappend r $msg
    77  } {0 {hello 16}}
    78  
    79  # Drop the table with the strange name.
    80  #
    81  do_test quote-1.6 {
    82    set r [catch {
    83      execsql {DROP TABLE '@abc'}
    84    } msg ]
    85    lappend r $msg
    86  } {0 {}}
    87   
    88  
    89  finish_test