ELSE in FOR loops - Python
http://stackoverflow.com/a/9980160
Turns out that you can use ELSE after a FOR loop to make it give an output if it didn’t have anything to iterate.
http://stackoverflow.com/a/9980160
Turns out that you can use ELSE after a FOR loop to make it give an output if it didn’t have anything to iterate.
I followed these instructions to gitignore an already committed file: http://stackoverflow.com/questions/6535362/gitignore-after-commit
When I wanted to start tracking it again, I needed to following these instructions: https://gist.github.com/laszlomiklosik/3833968
Make sure you save a backup of your current version before you check out the file again.
The problem: You have multiple DSNs defined in your unixODBC’s odbc.ini file, and it always connects to the same IP when you try testing with iSQL.
The solution:
DO NOT use the following line in your odbc.ini file to define your DSN’s port:
CommLinks = tcpip(host=localhost;port=9502)
DO use the following format:
CommLinks = tcpip(HOST=localhost:9502)
Sybase has a odbc parameter called “Compress” that is disabled by default. It’s very useful if you’re running queries on something with slow network transfer speeds and large datasets.
Example:
Compress = yes
This improve the performance of my query by about 40%.
The link to download SQLanywhere is here: http://www.sybase.com/detail?id=1087327
To install it, you need to unzip the file and run “./setup” in the top level directory in the unzipped folder.
I also installed:
https://github.com/mkleehammer/pyodbc
Installing unixODBC 2.3.2+ on Ubuntu 12.04 (archived)
The first error message I received was:
sqlanydb.InterfaceError: Could not load dbcapi. Tried: dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib
Exception AttributeError: "'Root' object has no attribute 'api'" in <bound method Root.__del__ of <sqlanydb.Root object at 0x3061150>> ignored
This error is resolved by creating a file called /etc/ld.so.conf.d/sqlanywhere.conf and adding a line with /opt/sqlanywhere12/lib64. Then you will need to run ldconfig -v.
The error message in the title occurred on Ubuntu because unixODBC was unable to find all of the libraries it needed to run.
This helped to find the issue: SQLAllocHandle on SQL_HANDLE_HENV, from Linux SQLNCLI driver (Microsoft Learn archive)
strace -t -f -o trace_out.txt isql -v <DSN>< USERNAME> <PASSWORD>
It will show there are a bunch of missing files. The issue was resolved when isql was run from the /opt/sqlanywhere12/bin64 directory. This indicated that it’s not looking in the right place for the library files. Run the following: export LD_LIBRARY_PATH='/opt/sqlanywhere12/lib64'
Not having the environmental variable above will also cause “sqlanydb.InterfaceError: dbcapi version 1 required.” if you’re using python’s sqlanydb library.
It will give a “file not found” error if you try using bin32/lib32 files on a 64 bit system. Make sure you use the bin64/lib64 files in the “Driver=” fild in your /etc/odbc.ini file (if you’re using a 64 bit system)!
Now you will receive an error saying “Parse error: DSN does not exist”. You need to add an ODBC_INI environmental variable to where your DSNs are defined. I ran the following: export ODBC_INI='/etc/odbc.ini'
To make those variables we exported work system-wide and continue to work even after we log out:
sudo nano /etc/environmentAdd:
ODBC_INI='/etc/odbc.ini'
LD_LIBRARY_PATH='/opt/sqlanywhere12/lib64'
These articles were helpful:
https://hynek.me/articles/twisted-sybase/
https://hynek.me/articles/a-short-summary-on-sybase-sql-anywhere-python/
Pros:
Cons:
I came across this error when I was trying to make a custom validator in Flask-Admin with wtforms form objects.
This code didn’t work:
def location_must_not_conflict(form, field):
if Event.query.filter(Event.location == form.location).first():
raise wtforms.validators.ValidationError('Location conflicts with another request for the same venue.')
Because I was using form.location and not form.location.data.
This will work:
def location_must_not_conflict(form, field):
if Event.query.filter(Event.location == form.location.data).first():
raise wtforms.validators.ValidationError('Location conflicts with another request for the same venue.')
On your edit and create templates in Flask-Admin, you can print individual form fields like this (the field’s name is location):
{{ form.location }}