xref: /sqlite-3.40.0/test/ptrchng.test (revision e8f52c50)
19310ef23Sdrh# 2007 April 27
29310ef23Sdrh#
39310ef23Sdrh# The author disclaims copyright to this source code.  In place of
49310ef23Sdrh# a legal notice, here is a blessing:
59310ef23Sdrh#
69310ef23Sdrh#    May you do good and not evil.
79310ef23Sdrh#    May you find forgiveness for yourself and forgive others.
89310ef23Sdrh#    May you share freely, never taking more than you give.
99310ef23Sdrh#
109310ef23Sdrh#***********************************************************************
119310ef23Sdrh# This file implements regression tests for SQLite library.
129310ef23Sdrh#
139310ef23Sdrh# The focus of the tests in this file are to verify that the
149310ef23Sdrh# underlying TEXT or BLOB representation of an sqlite3_value
159310ef23Sdrh# changes appropriately when APIs from the following set are
169310ef23Sdrh# called:
179310ef23Sdrh#
189310ef23Sdrh#     sqlite3_value_text()
199310ef23Sdrh#     sqlite3_value_text16()
209310ef23Sdrh#     sqlite3_value_blob()
219310ef23Sdrh#     sqlite3_value_bytes()
229310ef23Sdrh#     sqlite3_value_bytes16()
239310ef23Sdrh#
24*e8f52c50Sdrh# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $
259310ef23Sdrh
269310ef23Sdrhset testdir [file dirname $argv0]
279310ef23Sdrhsource $testdir/tester.tcl
289310ef23Sdrh
294152e677Sdanielk1977ifcapable !bloblit {
304152e677Sdanielk1977  finish_test
314152e677Sdanielk1977  return
324152e677Sdanielk1977}
334152e677Sdanielk1977
349310ef23Sdrh# Register the "pointer_change" SQL function.
359310ef23Sdrh#
369310ef23Sdrhsqlite3_create_function db
379310ef23Sdrh
389310ef23Sdrhdo_test ptrchng-1.1 {
399310ef23Sdrh  execsql {
409310ef23Sdrh    CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
419310ef23Sdrh    INSERT INTO t1 VALUES(1, 'abc');
429310ef23Sdrh    INSERT INTO t1 VALUES(2,
439310ef23Sdrh       'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
449310ef23Sdrh    INSERT INTO t1 VALUES(3, x'626c6f62');
459310ef23Sdrh    INSERT INTO t1 VALUES(4,
469310ef23Sdrh x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
479310ef23Sdrh    );
489310ef23Sdrh    SELECT count(*) FROM t1;
499310ef23Sdrh  }
509310ef23Sdrh} {4}
519310ef23Sdrh
529310ef23Sdrh# For the short entries that fit in the Mem.zBuf[], the pointer should
539310ef23Sdrh# never change regardless of what type conversions occur.
549310ef23Sdrh#
55a7a8e14bSdanielk1977# UPDATE: No longer true, as Mem.zBuf[] has been removed.
56a7a8e14bSdanielk1977#
579310ef23Sdrhdo_test ptrchng-2.1 {
589310ef23Sdrh  execsql {
599310ef23Sdrh    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
609310ef23Sdrh  }
619310ef23Sdrh} {0}
629310ef23Sdrhdo_test ptrchng-2.2 {
639310ef23Sdrh  execsql {
649310ef23Sdrh    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
659310ef23Sdrh  }
66131b0ef7Sdanielk1977} {0}
679310ef23Sdrhifcapable utf16 {
689310ef23Sdrh  do_test ptrchng-2.3 {
699310ef23Sdrh    execsql {
709310ef23Sdrh      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
719310ef23Sdrh    }
72a7a8e14bSdanielk1977  } {1}
739310ef23Sdrh  do_test ptrchng-2.4 {
749310ef23Sdrh    execsql {
759310ef23Sdrh      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
769310ef23Sdrh    }
77a7a8e14bSdanielk1977  } {1}
789310ef23Sdrh  do_test ptrchng-2.5 {
799310ef23Sdrh    execsql {
809310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
819310ef23Sdrh    }
829310ef23Sdrh  } {0}
839310ef23Sdrh  do_test ptrchng-2.6 {
849310ef23Sdrh    execsql {
859310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
869310ef23Sdrh    }
87a7a8e14bSdanielk1977  } {1}
889310ef23Sdrh}
899310ef23Sdrhdo_test ptrchng-2.11 {
909310ef23Sdrh  execsql {
919310ef23Sdrh    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
929310ef23Sdrh  }
939310ef23Sdrh} {0}
949310ef23Sdrhdo_test ptrchng-2.12 {
959310ef23Sdrh  execsql {
969310ef23Sdrh    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
979310ef23Sdrh  }
98131b0ef7Sdanielk1977} {0}
999310ef23Sdrhifcapable utf16 {
1009310ef23Sdrh  do_test ptrchng-2.13 {
1019310ef23Sdrh    execsql {
1029310ef23Sdrh      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
1039310ef23Sdrh    }
104a7a8e14bSdanielk1977  } {1}
1059310ef23Sdrh  do_test ptrchng-2.14 {
1069310ef23Sdrh    execsql {
1079310ef23Sdrh      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
1089310ef23Sdrh    }
109a7a8e14bSdanielk1977  } {1}
1109310ef23Sdrh  do_test ptrchng-2.15 {
1119310ef23Sdrh    execsql {
1129310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
1139310ef23Sdrh    }
1149310ef23Sdrh  } {0}
1159310ef23Sdrh  do_test ptrchng-2.16 {
1169310ef23Sdrh    execsql {
1179310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
1189310ef23Sdrh    }
119a7a8e14bSdanielk1977  } {1}
1209310ef23Sdrh}
1219310ef23Sdrh
1229310ef23Sdrh# For the long entries that do not fit in the Mem.zBuf[], the pointer
1239310ef23Sdrh# should change sometimes.
1249310ef23Sdrh#
1259310ef23Sdrhdo_test ptrchng-3.1 {
1269310ef23Sdrh  execsql {
1279310ef23Sdrh    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
1289310ef23Sdrh  }
1299310ef23Sdrh} {0}
1309310ef23Sdrhdo_test ptrchng-3.2 {
1319310ef23Sdrh  execsql {
1329310ef23Sdrh    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
1339310ef23Sdrh  }
134131b0ef7Sdanielk1977} {0}
1359310ef23Sdrhifcapable utf16 {
1369310ef23Sdrh  do_test ptrchng-3.3 {
1379310ef23Sdrh    execsql {
1389310ef23Sdrh      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
1399310ef23Sdrh    }
1409310ef23Sdrh  } {1}
1419310ef23Sdrh  do_test ptrchng-3.4 {
1429310ef23Sdrh    execsql {
1439310ef23Sdrh      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
1449310ef23Sdrh    }
1459310ef23Sdrh  } {1}
1469310ef23Sdrh  do_test ptrchng-3.5 {
1479310ef23Sdrh    execsql {
1489310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
1499310ef23Sdrh    }
1509310ef23Sdrh  } {0}
1519310ef23Sdrh  do_test ptrchng-3.6 {
1529310ef23Sdrh    execsql {
1539310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
1549310ef23Sdrh    }
1559310ef23Sdrh  } {1}
1569310ef23Sdrh}
1579310ef23Sdrhdo_test ptrchng-3.11 {
1589310ef23Sdrh  execsql {
1599310ef23Sdrh    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
1609310ef23Sdrh  }
1619310ef23Sdrh} {0}
1629310ef23Sdrhdo_test ptrchng-3.12 {
1639310ef23Sdrh  execsql {
1649310ef23Sdrh    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
1659310ef23Sdrh  }
166131b0ef7Sdanielk1977} {0}
1679310ef23Sdrhifcapable utf16 {
1689310ef23Sdrh  do_test ptrchng-3.13 {
1699310ef23Sdrh    execsql {
1709310ef23Sdrh      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
1719310ef23Sdrh    }
1729310ef23Sdrh  } {1}
1739310ef23Sdrh  do_test ptrchng-3.14 {
1749310ef23Sdrh    execsql {
1759310ef23Sdrh      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
1769310ef23Sdrh    }
1779310ef23Sdrh  } {1}
1789310ef23Sdrh  do_test ptrchng-3.15 {
1799310ef23Sdrh    execsql {
1809310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
1819310ef23Sdrh    }
1829310ef23Sdrh  } {0}
1839310ef23Sdrh  do_test ptrchng-3.16 {
1849310ef23Sdrh    execsql {
1859310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
1869310ef23Sdrh    }
1879310ef23Sdrh  } {1}
1889310ef23Sdrh}
1899310ef23Sdrh
1909310ef23Sdrh# A call to _bytes() should never reformat a _text() or _blob().
1919310ef23Sdrh#
1929310ef23Sdrhdo_test ptrchng-4.1 {
1939310ef23Sdrh  execsql {
1949310ef23Sdrh    SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
1959310ef23Sdrh  }
1969310ef23Sdrh} {0 0 0 0}
1979310ef23Sdrhdo_test ptrchng-4.2 {
1989310ef23Sdrh  execsql {
1999310ef23Sdrh    SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
2009310ef23Sdrh  }
2019310ef23Sdrh} {0 0 0 0}
2029310ef23Sdrh
2039310ef23Sdrh# A call to _blob() should never trigger a reformat
2049310ef23Sdrh#
2059310ef23Sdrhdo_test ptrchng-5.1 {
2069310ef23Sdrh  execsql {
2079310ef23Sdrh    SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
2089310ef23Sdrh  }
2099310ef23Sdrh} {0 0 0 0}
2109310ef23Sdrhifcapable utf16 {
2119310ef23Sdrh  do_test ptrchng-5.2 {
2129310ef23Sdrh    execsql {
2139310ef23Sdrh      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
2149310ef23Sdrh    }
2159310ef23Sdrh  } {0 0 0 0}
2169310ef23Sdrh  do_test ptrchng-5.3 {
2179310ef23Sdrh    execsql {
2189310ef23Sdrh      SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
2199310ef23Sdrh    }
2209310ef23Sdrh  } {0 0 0 0}
2219310ef23Sdrh}
2229310ef23Sdrh
2239310ef23Sdrhfinish_test
224