Connect to SMS Database

Under the hood, Rattail uses pyodbc to connect to the SMS database. Therefore in addition to editing rattail.conf, you must create a Data Source Name (DSN).

How you go about creating a DSN will vary depending on which operating system you’re using. I’ll only document the Windows method here, but rest assured that Linux can talk to SMS as well. (Some day that also will be documented. ;)

Create a DSN

In Windows, you can (Start ->) run the command odbcad32 to be shown the ODBC Data Source Administrator. Go to the System DSN tab and click Add, then choose SQL Server for the driver.

Provide a name for the data source, and choose the server to which you wish to connect. Configure the authentication etc. to your liking but make sure you do choose a default database for the data source. You will set this to your SMS database of course.

Configure Rattail

Edit your rattail.conf file so it includes something like the following:

[rattail]
init = ['rattail.sw.locsms']

[rattail.sw.locsms]
sqlalchemy.url = mssql://MJ001901-SMS

The “MJ001901-SMS” in the above is the name of the data source I created in the previous step. SQLAlchemy’s engine_from_config() is used to create the engine.

Talk to SMS

Now the fun part:

C:\tmp>rattail shell
Rattail v0.2a2 launching Python shell...

conf file(s): [
    'C:\envs\rattail.mamajeans\app\rattail.conf' ]

init()ed: [
    'rattail',
    'rattail.sw.locsms' ]

>>> locsms.__version__
'0.2a1'
>>> from rattail.sw.locsms import *
>>> s = Session()
>>> s.query(Product).count()
29857
>>> p = s.query(Product).get('0007430500132')
>>> p
<Product: 0007430500132>
>>> p.F29
'Apple Cidr Vingr'
>>> p.subdepartment
<Subdepartment: 600 Grocery: (catch-all)>
>>> p.price
<Price: 0007430500132: 5.6000/1.0>
>>> p.price.F30
Decimal('5.6000')
>>>

Table Of Contents

Previous topic

Rattail Package rattail.sw.locsms

Next topic

rattail.sw.locms

This Page