Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
example of SQLite using a local database file through SQLalchemy

Here's an example of SQLite using a local database file through SQLalchemy. The SQL statements are hidden from the user - that's the "Object to Relation Mapping" - although you can ask what's going on by runing my program with a -v option. ... example program source [here], seeding data download from [here].

We start by seeing if the database file exists:
  database = "stations.db"
  populated = os.path.exists(database)

So that we only have to populate the tables if they don't exist (we have a seeding data file).

Here's output from a typical run:
  WomanWithCat:flask grahamellis$ python orm_sqlite
  Station (code='MKM', postcode='SN12 8BN', footfall='23930', fullname='Melksham')
  (u'TEA', 8, u'Tees-Side Airport')
  (u'SPP', 12, u'Shippea Hill')
  (u'RDS', 26, u'Reddish South')
  (u'BYL', 40, u'Barry Links')
  (u'COE', 42, u'Coombe')
  (u'BRC', 64, u'Breich')
  (u'BUC', 80, u'Buckenham')
  (u'PIL', 88, u'Pilning')
  (u'GOF', 90, u'Golf Street')
  (u'DTN', 110, u'Denton')
  (u'KTL', 120, u'Kirton Lindsey')
  (u'ABC', 138, u'Altnabreac')
  (u'KIL', 144, u'Kildonan')
  (u'ELO', 166, u'Elton & Orston')
  (u'ACK', 176, u'Acklington')
  (u'AAT', 228, u'Achanalt')
  (u'CPN', 232, u'Chapelton')
  (u'SUG', 240, u'Sugar Loaf')
  (u'HEL', 276, u'Hensall')
  (u'HVN', 278, u'Havenhouse')
  (u'CLI', 298, u'Clifton')
  (u'SNT', 314, u'Stanlow & Thornton')
  (u'RWC', 314, u'Rawcliffe')
  (u'HBB', 334, u'Hubberts Bridge')
  (u'TPC', 340, u'Thorpe Culvert')
  (u'NCE', 348, u'New Clee')
  (u'SCT', 376, u'Scotscalder')
  (u'LAK', 378, u'Lakenheath')
  (u'SPN', 388, u'Spooner Row')
  (u'FOC', 498, u'Falls Of Cruachan')
  WomanWithCat:flask grahamellis$

(written 2015-10-14)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y113 - Python and SQL databases
  [2745] Connecting Python to sqlite and MySQL databases - (2010-04-28)
  [2746] Model - View - Controller demo, Sqlite - Python 3 - Qt4 - (2010-04-29)
  [2786] Factory methods and SqLite in use in a Python teaching example - (2010-05-29)
  [2790] Joining a MySQL table from within a Python program - (2010-06-02)
  [3136] A framework with python - Django - first steps - (2011-01-17)
  [3139] Steering our Python courses towards wxPython, SQLite and Django - (2011-01-19)
  [4024] SQL databases from Python - an SQLite example - (2013-03-02)
  [4086] Cacheing class for Python - using a local SQLite database as a key/value store - (2013-05-14)
  [4436] Accessing a MySQL database from Python with mysql.connector - (2015-02-21)
  [4445] Graphing presentations in Python - huge data, numpy and matplotlib - (2015-02-28)
  [4535] SQLAlchemy - first examples with a Python Object Relationship Mapping system - (2015-10-14)


Back to
Json load from URL, recursive display, Python 3.4
Previous and next
or
Horse's mouth home
Forward to
Flask and unittest - hello web app test world
Some other Articles
Setting up and tearing down with the Python with keyword
Unittest of a Flask application including forms
TransWilts public transport corridor
Flask and unittest - hello web app test world
example of SQLite using a local database file through SQLalchemy
Json load from URL, recursive display, Python 3.4
Flask - complete MVC site to navigate around a data set
Sessions in flask
Flask - first forms and responses with wtforms
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4537_exa ... chemy.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb