aboutsummaryrefslogtreecommitdiff
path: root/notes
diff options
context:
space:
mode:
Diffstat (limited to 'notes')
-rw-r--r--notes/notes1.txt55
-rw-r--r--notes/notes2.txt70
-rw-r--r--notes/notes2b.txt26
-rw-r--r--notes/notes3.txt165
4 files changed, 0 insertions, 316 deletions
diff --git a/notes/notes1.txt b/notes/notes1.txt
deleted file mode 100644
index 951711ea3..000000000
--- a/notes/notes1.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-unlocked -> read
-
- 1. If the journal file exists
- A. Open the journal file for exclusive access
- i) return SQLITE_BUSY
- B. Get a write lock on the database
- i) close the journal file
- ii) return SQLITE_PROTOCOL_ERROR
- C. playback the journal
- D. close and delete the journal file
- E. drop the write lock on the database
- 2. Get a read lock on the database file.
- A. return SQLITE_BUSY
- 3. return SQLITE_OK
-
-read -> unlocked
-
- 1. Drop the read lock on the database file
- 2. Invalidate all pages in the cache
- 3. return SQLITE_OK
-
-read -> write
-
- 1. Create the journal file and open for exclusive access
- A. return SQLITE_BUSY
- 2. Drop the read lock on the database
- 3. Get a write lock on the database
- A. Get a read lock on the database
- i) return SQLITE_PROTOCOL_ERROR
- B. Delete the journal
- C. return SQLITE_BUSY
- 4. return SQLITE_OK
-
-write -> read (commit)
-
- 1. Sync the journal
- 2. Write all dirty pages
- A. playback journal
- B. Reload or invalidate all pages in cache
- 3. Sync the database
- 4. Drop the write lock on the database
- 5. Get a read lock on the database
- A. return SQLITE_PROTOCOL_ERROR
- 6. Delete the journal
- 7. return SQLITE_OK
-
-write -> read (rollback)
-
- 1. Playback the journal
- 2. Drop the write lock on the database
- 3. Get a read lock on the database
- A. return SQLITE_PROTOCOL_ERROR
- 4. Delete the journal
- 5. Reload or invalidate all pages in cache
- 6. SQLITE_FULL
diff --git a/notes/notes2.txt b/notes/notes2.txt
deleted file mode 100644
index 3fb551b7a..000000000
--- a/notes/notes2.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-How to do a B-Tree insert:
-
- insert(data){
- create a new cursor
- move cursor to the entry nearest data
- if( cursor.key == keyof(data) ){
- replace cursor.data with dataof(data)
- return
- }
- childpg = NULL
- add_to_page(cursor, data+childpg)
- delete the cursor
- }
-
- add_to_page(cursor, data+childpg ){
- childpg->parent = cursor.page
- if( data+childpg fits on cursor.page ){
- insert data+childpg at cursor
- return
- }
- if( page==root ){
- split page+(data+childpg) into newpage1, center, newpage2
- cursor.page = &newpage1 + center + &newpage2;
- newpage1->parent = cursor.page
- newpage2->parent = cursor.page
- return
- }
- if( move_some_data_left || move_some_data_right ){
- insert data+childpg at cursor
- return
- }
- split page+(data+childpg) into page, center, newpage
- newpage->parent = page->parent
- move cursor to insertion point of center in parent page.
- add_to_page(cursor, center, (newpage));
- }
-
-How to do a B-Tree delete:
-
- delete(entry){
- if( entry is not a leaf ){
- p = predecessor of entry
- // note: if entry is not a leaf then p must
- // exist and must be a leaf
- free(entry.overflowptr)
- resize entry so that is is big enough to hold p.payload
- entry.payload = p.payload
- entry.overflowptr = p.overflowptr
- p.overflowptr = NULL
- delete(p)
- return
- }
- unlink entry from its page
- refill(page containing entry)
- }
-
- refill(page){
- if( page is more than half full ) return
- if( page is the root and contains no entries ){
- copy the one child page into this page thus reducing
- the height of the tree by one.
- return
- }
- if( able to merge page with neighbors ){
- do the merge
- refill(parent page)
- return
- }
- borrow entrys from neighbors
- }
diff --git a/notes/notes2b.txt b/notes/notes2b.txt
deleted file mode 100644
index e9d227444..000000000
--- a/notes/notes2b.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-add_to_page(cursor, payload, child){
- if( fits-on-current-page ){
- insert (child,payload) into cursor
- return
- }
- if( cursor is root page ){
- split cursor+(child,payload) into page1, center, page2
- set cursor page to page1,center,page2
- return
- }
- if( move_some_data_left || move_some_data_right ){
- add (child,payload) to cursor
- return
- }
- split cursor+(child,payload) into self, center, page2
- move_up(cursor)
- add_to_page(cursor, center, page2)
-}
-
-
-split(in_page, payload, child_pgno, out_page1, center_payload, out_page2){
- // It might be that in_page==out_page1
-
-}
diff --git a/notes/notes3.txt b/notes/notes3.txt
deleted file mode 100644
index 19d07768d..000000000
--- a/notes/notes3.txt
+++ /dev/null
@@ -1,165 +0,0 @@
-The Proposed New SQLite 2.0 Interface design. (April 16, 2001)
-
-Primary access routines:
- Control functions:
- sqlite *sqlite_open(const char *zFilename);
- int sqlite_compile(sqlite*, const char *zSql);
- int sqlite_next(sqlite*);
- int sqlite_abort(sqlite*);
- int sqlite_finish(sqlite*);
- sqlite *sqlite_dup(sqlite*);
- int sqlite_close(sqlite*);
- Access functions:
- int sqlite_status(sqlite*);
- char *sqlite_error_text(sqlite*);
- int sqlite_column_count(sqlite*);
- char **sqlite_column_names(sqlite*);
- char **sqlite_values(sqlite*);
- const char sqlite_version[];
- const char sqlite_encoding[];
-
-Secondary access routines:
- Control functions:
- int sqlite_complete(const char *);
- char *sqlite_mprintf(const char *zFormat, ...)
- char *sqlite_vmprintf(const char *zFormat, va_list ap);
- int sqlite_compile_printf(sqlite*, const char *zFormat, ...);
- int sqlite_compile_vprintf(sqlite*, const char *zFormat, va_list ap);
- int sqlite_eval(sqlite*, const char *zSql);
- int sqlite_retry(sqlite*);
- int sqlite_eval_printf(sqlite*, const char *zFormat, ...);
- int sqlite_eval_vprintf(sqlite*, const char *zFormat, va_list ap);
- int sqlite_busy_handler(sqlite*, int(*)(void*,const char*,int), void*);
- int sqlite_busy_timeout(sqlite*, int ms);
- Access functions:
- int sqlite_row_count(sqlite*);
- char ***sqlite_rows(sqlite*, int iRow);
-
-Usage examples:
- Getting an entire result table in one go:
- sqlite *p = sqlite_open("ex.db");
- sqlite_eval(p, "SELECT * FROM table_one");
- for(i=0; i<sqlite_row_count(p); i++){
- if( i>0 ) printf("\n");
- for(j=0; j<sqlite_column_count(p); j++){
- printf("%s = %s\n", sqlite_column_names(p)[j], sqlite_row(p,i)[j]);
- }
- }
- sqlite_close(p);
-
- Getting one row at a time:
- sqlite *p = sqlite_open("ex.db");
- sqlite_compile(p, "SELECT * FROM table_one");
- for(i=0; sqlite_next(p)==SQLITE_OK; i++ ){
- if( i>0 ) printf("\n");
- for(j=0; j<sqlite_column_count(p); j++){
- printf("%s = %s\n", sqlite_column_names(p)[j], sqlite_values(p)[j];
- }
- }
- sqlite_close(p);
-
- Getting an entire result table with error and lock detection:
- sqlite *p = sqlite_open("ex.db");
- if( p==0 ){
- fprintf(stderr,"out of memory");
- return;
- }
- if( sqlite_status(p)!=SQLITE_OK ){
- fprintf(stderr,"Error opening database: %s", sqlite_error_text(p));
- sqlite_close(p);
- return;
- }
- sqlite_busy_timeout(p, 5000);
- sqlite_eval(p, "SELECT * FROM table_one");
- if( sqlite_status(p)!=SQLITE_OK ){
- fprintf(stderr,"Query error: %s\n", sqlite_error_text(p));
- sqlite_close(p);
- return;
- }
- for(i=0; i<sqlite_row_count(p); i++){
- if( i>0 ) printf("\n");
- for(j=0; j<sqlite_column_count(p); j++){
- printf("%s = %s\n", sqlite_column_names(p)[j], sqlite_row(p,i)[j]);
- }
- }
- sqlite_close(p);
-
- Getting one row at a time with manual control of lock conflicts:
- sqlite *p = sqlite_open("ex.db");
- if( p==0 ){
- fprintf(stderr,"out of memory");
- return;
- }
- if( sqlite_status(p)!=SQLITE_OK ){
- fprintf(stderr,"Error opening database: %s", sqlite_error_text(p));
- sqlite_close(p);
- return;
- }
- sqlite_compile(p, "SELECT * FROM table_one");
- if( sqlite_status(p)!=SQLITE_OK ){
- fprintf(stderr,"Query error: %s\n", sqlite_error_text(p));
- sqlite_close(p);
- return;
- }
- for(i=0; sqlite_status(p)==SQLITE_OK; i++ ){
- for(j=0; j<50 && sqlite_next(p)==SQLITE_BUSY; j++){
- usleep(100000);
- }
- if( sqlite_status(p)!=SQLITE_OK ) break;
- if( i>0 ) printf("\n");
- for(j=0; j<sqlite_column_count(p); j++){
- printf("%s = %s\n", sqlite_column_names(p)[j], sqlite_values(p)[j];
- }
- }
- sqlite_close(p);
-
-TCL Interface
-
- sqlite DB FILENAME ?MODE?
- DB compile SQL
- DB next
- DB status
- DB errortext
- DB row VAR
- DB argc
- DB argv ?N?
- DB table ?VAR?
- DB columns ?N?
- DB finish
- DB abort
- DB eval SQL ?VAR SCRIPT?
- DB close
- DB complete
- DB timeout MS
- DB busy SCRIPT
- DB dup NEWDB
-
-Primary access pattern:
-
- sqlite *db = sqlite_open("testdb", 0644);
- sqlite_compile(db, "SELECT * FROM sqlite_master");
- while( sqlite_row(db, &argc, &argv)==SQLITE_OK ){
- /* Do something with the row data in argc, argv */
- }
- sqlite_finish(db);
- sqlite_close(db);
-
-Alternative access pattern 1:
-
- sqlite *db = sqlite_open("testdb", 0644);
- sqlite_compile(db, "SELECT * FROM sqlite_master");
- sqlite_table(db, &nrow, &ncolumn, &argv);
- /* Do something with the matrix data in argv */
- sqlite_finish(db);
- sqlite_close(db);
-
-Issues:
-
- * If one query is in progress and we do sqlite_compile(), does
- that abort the current query or return an error code?
-
- * What happens here:
- sqlite_compile(db, "SELECT a FROM t1; SELECT b,c FROM t2;");
- sqlite_table(db, &nrow, &ncolumn, &argv);
- What value is returned for nrow and ncolumn? Or is this an error?
- Or maybe only the first table is returned?