diff --git a/inst/@octave_sqlite/commit.m b/inst/@octave_sqlite/commit.m index e0430d2..2769bc5 100644 --- a/inst/@octave_sqlite/commit.m +++ b/inst/@octave_sqlite/commit.m @@ -18,7 +18,7 @@ ## -*- texinfo -*- ## @deftypefn {} {} commit (@var{db}) -## Commit pending transactions of sqlite connection. +## Commit pending transactions of sqlite connection that has AutoCommit = off. ## ## @subsubheading Inputs ## @table @asis @@ -29,6 +29,22 @@ ## @subsubheading Outputs ## None ## +## @subsubheading Examples +## Create a database table turn off autocommit and insert a row and commit +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## # create table +## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)'); +## # turn off auto commit +## db.AutoCommit = "off"; +## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")'); +## # commit the insert +## commit(db); +## } +## @end example +## ## @seealso{sqlite, rollback} ## @end deftypefn diff --git a/inst/@octave_sqlite/execute.m b/inst/@octave_sqlite/execute.m index e369855..7042cbb 100644 --- a/inst/@octave_sqlite/execute.m +++ b/inst/@octave_sqlite/execute.m @@ -31,6 +31,18 @@ ## @subsubheading Inputs ## None ## +## @subsubheading Examples +## Create a database table and insert a row +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## # create table and then insert a row +## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)'); +## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")'); +## } +## @end example +## ## @seealso{sqlite, fetch} ## @end deftypefn diff --git a/inst/@octave_sqlite/fetch.m b/inst/@octave_sqlite/fetch.m index a5b0ac4..c93a8ad 100644 --- a/inst/@octave_sqlite/fetch.m +++ b/inst/@octave_sqlite/fetch.m @@ -43,6 +43,25 @@ ## a table containing the query result. ## @end table ## +## @subsubheading Examples +## Select all rows of data from a database tables +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## data = fetch(db, 'SELECT * FROM TestTable'); +## } +## @end example +## +## Select 5 rows of data from a database tables +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## data = fetch(db, 'SELECT * FROM TestTable', "MaxRows", 5); +## } +## @end example +## ## @seealso{sqlite, sqlread} ## @end deftypefn diff --git a/inst/@octave_sqlite/rollback.m b/inst/@octave_sqlite/rollback.m index 340604f..79a6ae4 100644 --- a/inst/@octave_sqlite/rollback.m +++ b/inst/@octave_sqlite/rollback.m @@ -29,6 +29,22 @@ ## @subsubheading Outputs ## None ## +## @subsubheading Examples +## Create a database table and insert a row, then roll back the insert +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## # create table +## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)'); +## # turn off auto commit +## db.AutoCommit = "off"; +## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")'); +## # roll back the insert +## rollback(db); +## } +## @end example +## ## @seealso{sqlite, commit} ## @end deftypefn diff --git a/inst/@octave_sqlite/sqlread.m b/inst/@octave_sqlite/sqlread.m index 16098c1..88632ee 100644 --- a/inst/@octave_sqlite/sqlread.m +++ b/inst/@octave_sqlite/sqlread.m @@ -45,6 +45,25 @@ ## a table containing the query result. ## @end table ## +## @subsubheading Examples +## Select all rows of data from a database table +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## data = sqlread(db, 'TestTable'); +## } +## @end example +## +## Select 5 rows of data from a database table +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## data = sqlread(db, 'TestTable', "MaxRows", 5); +## } +## @end example +## ## @seealso{sqlite, fetch} ## @end deftypefn diff --git a/inst/@octave_sqlite/sqlwrite.m b/inst/@octave_sqlite/sqlwrite.m index eaa18e4..70be314 100644 --- a/inst/@octave_sqlite/sqlwrite.m +++ b/inst/@octave_sqlite/sqlwrite.m @@ -48,6 +48,19 @@ ## @subsubheading Outputs ## None ## +## @subsubheading Examples +## Create a database table and insert a row +## @example +## @code { +## # create sql connection +## db = sqlite("mytest.db"); +## # create table (if doesnt exist) and then insert 2 rows +## t = dbtable([1;2],['Name1';'Name2'], 'VariableNames', @{'Id','Name'@}); +## # insert table data +## sqlwrite(db, "Test", t, 'ColumnType', @{'numeric', 'text'@}); +## } +## @end example +## ## @seealso{sqlite, execute} ## @end deftypefn diff --git a/inst/dbtable.m b/inst/dbtable.m index 3b1af35..3e3c687 100644 --- a/inst/dbtable.m +++ b/inst/dbtable.m @@ -62,6 +62,33 @@ ## User data value ## @end table ## @end table + ## + ## @subsubheading Examples + ## Directly create a 2 column table from input of each column + ## @example + ## @code { + ## t = dbtable([0;1;3], [2;4;6]); + ## } + ## @end example + ## + ## Directly create a 2 column table from input of each column, and specify variable + ## names + ## @example + ## @code { + ## t = dbtable([0;1;3], [2;4;6], "VariableNames", @{'Variable1', 'Variable2'@}); + ## } + ## @end example + ## + ## Create a 2 column table from 2 variables V1, V2 + ## @example + ## @code { + ## V1 = [0;1;3]; + ## V2 = [2;4;6]; + ## t = dbtable(V1, V2); + ## } + ## @end example + ## + ## @seealso{readdbtable, struct2dbtable} ## @end deftypefn properties (Access = private)