Skip to content

Commit d832db5

Browse files
authored
Merge pull request #5 from gnu-octave/devel
add additional examples to func docs
2 parents 92b96bd + 8d79de3 commit d832db5

File tree

7 files changed

+123
-1
lines changed

7 files changed

+123
-1
lines changed

inst/@octave_sqlite/commit.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
## -*- texinfo -*-
2020
## @deftypefn {} {} commit (@var{db})
21-
## Commit pending transactions of sqlite connection.
21+
## Commit pending transactions of sqlite connection that has AutoCommit = off.
2222
##
2323
## @subsubheading Inputs
2424
## @table @asis
@@ -29,6 +29,22 @@
2929
## @subsubheading Outputs
3030
## None
3131
##
32+
## @subsubheading Examples
33+
## Create a database table turn off autocommit and insert a row and commit
34+
## @example
35+
## @code {
36+
## # create sql connection
37+
## db = sqlite("mytest.db");
38+
## # create table
39+
## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)');
40+
## # turn off auto commit
41+
## db.AutoCommit = "off";
42+
## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")');
43+
## # commit the insert
44+
## commit(db);
45+
## }
46+
## @end example
47+
##
3248
## @seealso{sqlite, rollback}
3349
## @end deftypefn
3450

inst/@octave_sqlite/execute.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
## @subsubheading Inputs
3232
## None
3333
##
34+
## @subsubheading Examples
35+
## Create a database table and insert a row
36+
## @example
37+
## @code {
38+
## # create sql connection
39+
## db = sqlite("mytest.db");
40+
## # create table and then insert a row
41+
## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)');
42+
## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")');
43+
## }
44+
## @end example
45+
##
3446
## @seealso{sqlite, fetch}
3547
## @end deftypefn
3648

inst/@octave_sqlite/fetch.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@
4343
## a table containing the query result.
4444
## @end table
4545
##
46+
## @subsubheading Examples
47+
## Select all rows of data from a database tables
48+
## @example
49+
## @code {
50+
## # create sql connection
51+
## db = sqlite("mytest.db");
52+
## data = fetch(db, 'SELECT * FROM TestTable');
53+
## }
54+
## @end example
55+
##
56+
## Select 5 rows of data from a database tables
57+
## @example
58+
## @code {
59+
## # create sql connection
60+
## db = sqlite("mytest.db");
61+
## data = fetch(db, 'SELECT * FROM TestTable', "MaxRows", 5);
62+
## }
63+
## @end example
64+
##
4665
## @seealso{sqlite, sqlread}
4766
## @end deftypefn
4867

inst/@octave_sqlite/rollback.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
## @subsubheading Outputs
3030
## None
3131
##
32+
## @subsubheading Examples
33+
## Create a database table and insert a row, then roll back the insert
34+
## @example
35+
## @code {
36+
## # create sql connection
37+
## db = sqlite("mytest.db");
38+
## # create table
39+
## execute(db, 'CREATE TABLE Test (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)');
40+
## # turn off auto commit
41+
## db.AutoCommit = "off";
42+
## execute(db, 'INSERT INTO Test (Name) VALUES ("Line1")');
43+
## # roll back the insert
44+
## rollback(db);
45+
## }
46+
## @end example
47+
##
3248
## @seealso{sqlite, commit}
3349
## @end deftypefn
3450

inst/@octave_sqlite/sqlread.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@
4545
## a table containing the query result.
4646
## @end table
4747
##
48+
## @subsubheading Examples
49+
## Select all rows of data from a database table
50+
## @example
51+
## @code {
52+
## # create sql connection
53+
## db = sqlite("mytest.db");
54+
## data = sqlread(db, 'TestTable');
55+
## }
56+
## @end example
57+
##
58+
## Select 5 rows of data from a database table
59+
## @example
60+
## @code {
61+
## # create sql connection
62+
## db = sqlite("mytest.db");
63+
## data = sqlread(db, 'TestTable', "MaxRows", 5);
64+
## }
65+
## @end example
66+
##
4867
## @seealso{sqlite, fetch}
4968
## @end deftypefn
5069

inst/@octave_sqlite/sqlwrite.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
## @subsubheading Outputs
4949
## None
5050
##
51+
## @subsubheading Examples
52+
## Create a database table and insert a row
53+
## @example
54+
## @code {
55+
## # create sql connection
56+
## db = sqlite("mytest.db");
57+
## # create table (if doesnt exist) and then insert 2 rows
58+
## t = dbtable([1;2],['Name1';'Name2'], 'VariableNames', @{'Id','Name'@});
59+
## # insert table data
60+
## sqlwrite(db, "Test", t, 'ColumnType', @{'numeric', 'text'@});
61+
## }
62+
## @end example
63+
##
5164
## @seealso{sqlite, execute}
5265
## @end deftypefn
5366

inst/dbtable.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@
6262
## User data value
6363
## @end table
6464
## @end table
65+
##
66+
## @subsubheading Examples
67+
## Directly create a 2 column table from input of each column
68+
## @example
69+
## @code {
70+
## t = dbtable([0;1;3], [2;4;6]);
71+
## }
72+
## @end example
73+
##
74+
## Directly create a 2 column table from input of each column, and specify variable
75+
## names
76+
## @example
77+
## @code {
78+
## t = dbtable([0;1;3], [2;4;6], "VariableNames", @{'Variable1', 'Variable2'@});
79+
## }
80+
## @end example
81+
##
82+
## Create a 2 column table from 2 variables V1, V2
83+
## @example
84+
## @code {
85+
## V1 = [0;1;3];
86+
## V2 = [2;4;6];
87+
## t = dbtable(V1, V2);
88+
## }
89+
## @end example
90+
##
91+
## @seealso{readdbtable, struct2dbtable}
6592
## @end deftypefn
6693

6794
properties (Access = private)

0 commit comments

Comments
 (0)