-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from thombashi/develop
Develop
- Loading branch information
Showing
18 changed files
with
586 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ Examples | |
|
||
create_table | ||
insert_record | ||
update | ||
get_profile | ||
in_memory_database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Update a record in a table | ||
-------------------------- | ||
|
||
:py:meth:`~simplesqlite.core.SimpleSQLite.update` | ||
method can update record(s) in a table. | ||
|
||
|
||
.. code:: python | ||
from simplesqlite import SimpleSQLite | ||
from simplesqlite.sqlquery import SqlQuery | ||
import six | ||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
data_matrix = [ | ||
[1, "aaa"], | ||
[2, "bbb"], | ||
] | ||
con.create_table_with_data( | ||
table_name, | ||
attribute_name_list=["key", "value"], | ||
data_matrix=data_matrix) | ||
six.print_("---- before update ----") | ||
for record in con.select(select="*", table_name=table_name).fetchall(): | ||
six.print_(record) | ||
six.print_() | ||
con.update( | ||
table_name, | ||
set_query="value = 'ccc'", | ||
where=SqlQuery.make_where(key="key", value=1)) | ||
six.print_("---- after update ----") | ||
for record in con.select(select="*", table_name=table_name).fetchall(): | ||
six.print_(record) | ||
.. code-block:: console | ||
---- before update ---- | ||
(1, u'aaa') | ||
(2, u'bbb') | ||
---- after update ---- | ||
(1, u'ccc') | ||
(2, u'bbb') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, NullDatabaseConnectionError | ||
import six | ||
|
||
|
||
con = SimpleSQLite("sample.sqlite", "w") | ||
|
||
six.print_("---- connected to a database ----") | ||
con.check_connection() | ||
|
||
six.print_("---- disconnected from a database ----") | ||
con.close() | ||
try: | ||
con.check_connection() | ||
except NullDatabaseConnectionError as e: | ||
six.print_(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, TableNotFoundError | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name=table_name, | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
|
||
six.print_(con.get_attribute_name_list(table_name)) | ||
|
||
try: | ||
six.print_(con.get_attribute_name_list("not_existing")) | ||
except TableNotFoundError as e: | ||
six.print_(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
import six | ||
|
||
|
||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name="hoge", | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
six.print_(con.get_table_name_list()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, TableNotFoundError | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name=table_name, | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
|
||
six.print_(con.has_attribute(table_name, "attr_a")) | ||
six.print_(con.has_attribute(table_name, "not_existing")) | ||
try: | ||
six.print_(con.has_attribute("not_existing", "attr_a")) | ||
except TableNotFoundError as e: | ||
six.print_(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, TableNotFoundError | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name=table_name, | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
|
||
six.print_(con.has_attribute_list(table_name, ["attr_a"])) | ||
six.print_(con.has_attribute_list(table_name, ["attr_a", "attr_b"])) | ||
six.print_(con.has_attribute_list( | ||
table_name, ["attr_a", "attr_b", "not_existing"])) | ||
try: | ||
six.print_(con.has_attribute("not_existing", ["attr_a"])) | ||
except TableNotFoundError as e: | ||
six.print_(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
import six | ||
|
||
|
||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name="hoge", | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
six.print_(con.has_table("hoge")) | ||
six.print_(con.has_table("not_existing")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
import six | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite | ||
from simplesqlite.sqlquery import SqlQuery | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
|
||
data_matrix = [ | ||
[1, "aaa"], | ||
[2, "bbb"], | ||
] | ||
con.create_table_with_data( | ||
table_name, | ||
attribute_name_list=["key", "value"], | ||
data_matrix=data_matrix) | ||
|
||
six.print_("---- before update ----") | ||
for record in con.select(select="*", table_name=table_name).fetchall(): | ||
six.print_(record) | ||
six.print_() | ||
|
||
con.update( | ||
table_name, | ||
set_query="value = 'ccc'", | ||
where=SqlQuery.make_where(key="key", value=1)) | ||
|
||
six.print_("---- after update ----") | ||
for record in con.select(select="*", table_name=table_name).fetchall(): | ||
six.print_(record) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, TableNotFoundError, AttributeNotFoundError | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name=table_name, | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
|
||
con.verify_attribute_existence(table_name, "attr_a") | ||
try: | ||
con.verify_attribute_existence(table_name, "not_existing") | ||
except AttributeNotFoundError as e: | ||
six.print_(e) | ||
try: | ||
con.verify_attribute_existence("not_existing", "attr_a") | ||
except TableNotFoundError as e: | ||
six.print_(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
|
||
from simplesqlite import SimpleSQLite, TableNotFoundError | ||
import six | ||
|
||
|
||
table_name = "sample_table" | ||
con = SimpleSQLite("sample.sqlite", "w") | ||
con.create_table_with_data( | ||
table_name=table_name, | ||
attribute_name_list=["attr_a", "attr_b"], | ||
data_matrix=[[1, "a"], [2, "b"]]) | ||
|
||
con.verify_table_existence(table_name) | ||
try: | ||
con.verify_table_existence("not_existing") | ||
except TableNotFoundError as e: | ||
six.print_(e) |
Oops, something went wrong.