Skip to content

Commit fdf8b93

Browse files
committed
Fix doc test problem
1 parent 00036fb commit fdf8b93

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

doc/source/sqlalchemy.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Suppose we have a pure sql database connection via sqlalchemy:
77
>>> from sqlalchemy.ext.declarative import declarative_base
88
>>> from sqlalchemy import Column , Integer, String, Float, Date
99
>>> from sqlalchemy.orm import sessionmaker
10-
>>> engine=create_engine("sqlite:///tmp.db")
10+
>>> engine=create_engine("sqlite:///sqlalchemy.db")
1111
>>> Base=declarative_base()
1212
>>> Session=sessionmaker(bind=engine)
1313

@@ -24,12 +24,11 @@ Assume we have the following database table::
2424
... weight=Column(Float)
2525
... birth=Column(Date)
2626

27-
Let's clear the database and create previous table in the database:
27+
Let's clear the database and create previous table in the database::
2828

29-
>>> Base.metadata.drop_all(engine)
3029
>>> Base.metadata.create_all(engine)
3130

32-
And suppose we have the following data structure to be saved:
31+
And suppose we have the following data structure to be saved::
3332

3433
>>> import datetime
3534
>>> data = [
@@ -191,4 +190,4 @@ Let's use previous data for reading and see if we could get them via
191190

192191
>>> mysession.close()
193192
>>> import os
194-
>>> os.unlink('tmp.db')
193+
>>> os.unlink('sqlalchemy.db')

pyexcel_io/sqlbook.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ def sheets(self):
6060
class SQLTableWriter(SheetWriter):
6161
"""Write to a table
6262
"""
63-
def __init__(self, session, table_params, **keywords):
63+
def __init__(self, session, table_params, auto_commit=True, **keywords):
6464
self.session = session
6565
self.table = None
6666
self.initializer = None
6767
self.mapdict = None
6868
self.column_names = None
69+
self.auto_commit = auto_commit
6970
self.keywords = keywords
7071
if len(table_params) == 4:
7172
self.table, self.column_names, self.mapdict, self.initializer = table_params
@@ -98,7 +99,7 @@ def _write_row(self, array):
9899
self.session.add(o)
99100

100101
def close(self):
101-
if 'auto_commit' in self.keywords and self.keywords['auto_commit'] == True:
102+
if self.auto_commit:
102103
self.session.commit()
103104

104105

0 commit comments

Comments
 (0)