# 2012 January 4 {} # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # # This file implements tests for how the recover module handles cell # overflow. # # $Id$ set testdir [file dirname $argv0] source $testdir/tester.tcl set lorem "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sagittis gravida odio vitae ultrices. Nulla facilisi. Maecenas pulvinar, tellus ut bibendum semper, nibh tellus auctor nulla, in dignissim nisi ipsum id arcu. Nullam tincidunt arcu malesuada turpis faucibus in adipiscing enim mattis. Fusce augue magna, scelerisque sollicitudin egestas in, cursus eu sapien. Pellentesque tempor risus at lectus convallis a convallis orci ornare. Integer tristique aliquam leo vel interdum. Phasellus quis dictum nisi. Curabitur at enim non felis pharetra imperdiet. Duis tempus massa eu leo varius porta. Vestibulum sodales nulla at purus tincidunt ultrices. Nam euismod posuere nibh, nec sodales magna luctus ac. Ut commodo hendrerit mauris vitae gravida. In interdum justo ut sem eleifend convallis. Donec cursus molestie elementum. Suspendisse at nisl tellus, vel consequat mauris. Nullam non justo nibh. Maecenas varius sollicitudin libero, nec feugiat turpis facilisis eget. Quisque et sem risus. Aenean a magna quis purus hendrerit mattis eu vel lorem. Aenean fringilla diam eget tortor lacinia sed mollis eros feugiat. Quisque ac purus sapien. Nullam quis tellus vel magna convallis tincidunt. Donec eget ligula at libero tincidunt congue ut ut lacus. Integer dignissim aliquet congue. Pellentesque sed risus vitae lorem porta viverra ac eu risus. Vivamus congue suscipit odio pulvinar aliquet. Aliquam porttitor nunc non sapien auctor et vehicula augue molestie. Aliquam et dui ac sem tempus dictum. Fusce arcu nulla, viverra sit amet suscipit quis, malesuada at felis. Fusce ut diam felis. Fusce id ligula non eros fermentum sodales in nec quam. Donec tempor bibendum arcu ac adipiscing. Praesent nisl lectus, tempor ut vehicula eget, mattis a justo. Mauris condimentum luctus eros a varius. Morbi mollis elit eget velit convallis eu sodales odio egestas. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus interdum, metus sit amet varius varius, lectus eros semper risus, sed sagittis ipsum libero in sapien. Nam lacinia nulla vitae magna facilisis scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida dignissim eleifend. Aliquam vel tincidunt tortor. Curabitur massa ante, blandit a auctor at, ullamcorper sed nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse ut felis a eros egestas ultricies et quis mi. Vivamus ut risus massa. Donec nec ornare erat. Aliquam ornare, lorem a rhoncus aliquam, tellus diam tincidunt tellus, a mattis nunc ante ac arcu. Curabitur nec metus id risus commodo ullamcorper eu ut tortor." # Create a database which needs a multiple overflow pages to test the # transition from main page to overflow, and then overflow to # overflow. do_test recover-overflow-1.0 { db eval { DROP TABLE IF EXISTS overflow; CREATE TABLE overflow (value TEXT); INSERT INTO overflow VALUES ($lorem); DROP TABLE IF EXISTS overflow_recover; CREATE VIRTUAL TABLE temp.overflow_recover USING recover( overflow, value TEXT ); } # Should have root page, leaf page, and 2 overflow pages, because # length(value) is more than 2x page_size. execsql { PRAGMA page_count; PRAGMA page_size; SELECT rowid, TYPEOF(value), length(value), value FROM overflow_recover; } } [list 4 1024 1 text [string length $lorem] $lorem] # No overflow. [1024-35 == 990, overhead of 1-byte rowid, 2-byte # record length, 1-byte header length, 2-byte field type.] set substr [string range $lorem 0 985] do_test recover-overflow-1.1 { db eval { DROP TABLE IF EXISTS overflow; CREATE TABLE overflow (value TEXT); INSERT INTO overflow VALUES ($substr); DROP TABLE IF EXISTS overflow_recover; CREATE VIRTUAL TABLE temp.overflow_recover USING recover( overflow, value TEXT ); } # Trim to remove excess pages from prior tests. db eval {VACUUM} execsql { PRAGMA page_count; PRAGMA page_size; SELECT rowid, TYPEOF(value), length(value), value FROM overflow_recover; } } [list 2 1024 1 text [string length $substr] $substr] # One byte of overflow. set substr [string range $lorem 0 986] do_test recover-overflow-1.2 { db eval { DROP TABLE IF EXISTS overflow; CREATE TABLE overflow (value TEXT); INSERT INTO overflow VALUES ($substr); DROP TABLE IF EXISTS overflow_recover; CREATE VIRTUAL TABLE temp.overflow_recover USING recover( overflow, value TEXT ); } # Trim to remove excess pages from prior tests. db eval {VACUUM} execsql { PRAGMA page_count; PRAGMA page_size; SELECT rowid, TYPEOF(value), length(value), value FROM overflow_recover; } } [list 3 1024 1 text [string length $substr] $substr] # One full overflow page, plus maxLocal in-leaf. [985+1020] set substr [string range $lorem 0 2005] do_test recover-overflow-1.3 { db eval { DROP TABLE IF EXISTS overflow; CREATE TABLE overflow (value TEXT); INSERT INTO overflow VALUES ($substr); DROP TABLE IF EXISTS overflow_recover; CREATE VIRTUAL TABLE temp.overflow_recover USING recover( overflow, value TEXT ); } # Trim to remove excess pages from prior tests. db eval {VACUUM} execsql { PRAGMA page_count; PRAGMA page_size; SELECT rowid, TYPEOF(value), length(value), value FROM overflow_recover; } } [list 3 1024 1 text [string length $substr] $substr] # Overflow to a second overflow page. set substr [string range $lorem 0 2006] do_test recover-overflow-1.4 { db eval { DROP TABLE IF EXISTS overflow; CREATE TABLE overflow (value TEXT); INSERT INTO overflow VALUES ($substr); DROP TABLE IF EXISTS overflow_recover; CREATE VIRTUAL TABLE temp.overflow_recover USING recover( overflow, value TEXT ); } # Trim to remove excess pages from prior tests. db eval {VACUUM} execsql { PRAGMA page_count; PRAGMA page_size; SELECT rowid, TYPEOF(value), length(value), value FROM overflow_recover; } } [list 4 1024 1 text [string length $substr] $substr] finish_test