The Best Live Band Ever is performing May 4, 2019 at the legendary Carlyle Club

“The world’s best band” – that’s how Forbes magazine describes Doc Scantlin and his Imperial Palms Orchestra. It’s true, I’ve seen them several times and there is no better show imaginable. Doc and his amazing talents and his amazing friends will be performing at the Carlyle Club in Alexandria, Virginia, on May 4, 2019.

Here’s the link for tickets: Doc Scantlin and his Imperial Palms Orchestra at the Carlyle Club.

College Donations – An American Institution

Wealthy donors have contributed billions to America’s colleges and universities for years. The Chronicle for Higher Education, which I’ve often quoted in my companion website TrainingMagazine.com, published the following article citing a history of major contributions over the last few decades, going back to 1967:

Major Private Gifts to Higher Education

Some examples:

  • Michael Bloomberg to Johns Hopkins, several gifts totaling over $1 billion
  • Bill and Melinda Gates to University of Cambridge, over $200 million
  • Larry Ellison to University of Southern California (USC), over $200 million

The list is lengthy and the donors are interesting – it’s worth checking out.

Lori Loughlin & Husband: Not Guilty?

So there’s this:

Lori Loughlin & Husband Feel ‘Manipulated’ in College Scam: ‘They Had No Bad Intention,’ Source Says

It wouldn’t surprise me if Lori Loughlin and her husband are telling the truth.  There is, after all, a presumption of innocence in America – doesn’t that still  exist?  I wouldn’t be surprised if, in the final analysis, they end up

  1. convicted in lower court and
  2. fully exonerated on appeal

The reason I think that way is this fantastic 2014 book by Sidney Powell:

Licensed To Lie

It reads like a John Grisham novel, but is real.  Powell is a former federal prosecutor who defended one of the very many defendants to a series of cases brought on by the US Department of Justice’ Enron Task Force.  In her book, Powell details a pattern of overreach and legal abuse, documented in great detail and backed up by appellate court decisions – including at least one appellate court-ordered investigation.  It’s a stunning, maddening book, and when these “college scam” cases hit the news in the  last few weeks, I was reminded of her work.  The similarities are striking.

Time – and millions of dollars in legal fees – will tell.

The Real MIT Blackjack Team

I’ve been posting about th3 2008 film 21.  The video below is an interview with the real MIT blackjack team on whom the film is based.  They discuss the math behind their card counting scheme that won them anywhere from $10,000 to $500,000 per trip to Las Vegas as they “counted cards”.

21 (2008 film)

I posted earlier this week about an old Rihanna song and I mentioned that it’s featured in the 2008 film 21.  That’s a really interesting movie that tells the true story – sort of – of the MIT team that beat the blackjack tables in Las Vegas.  The methods they used are real, the movie embellishes a bit to create a rather sinister nemesis to make it a more compelling film.  But the core story is real. If you’ve seen it, it’s fun to watch.

Here’s the trailer:

Python

Earlier I posted about Python.  Since then I’ve worked a Python project that interacted with a SQL database using SQL Alchemy and got an opportunity to do quite a bit in the way of data transformation and data integration, leveraging Python’s remarkably flexible capabilities and rich libraries for use with analytics, machine learning and deep learning, and more.  It’s a great language.  I love Java but I can certainly see why Python has the momentum right now.  It’s an easy language to pick up.  Whereas a typical Java program requires quite a bit to reach the simple “Hello, World” test program, Python gets you there much more quickly.

print("Hello, world");

That’s it! Crazy easy. Compare this to Java:

public class demonstrateHelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Now – to be fair – there’s a reason this Java example is more involved, its due to Java’s requirement that code be structured in the form of a class. Python doesn’t require that but offers the same option. If you’ve seen this sort of Python code:

if __name__ == "__main__":
  print('Hello, world')

… then you know what I’m talking about.

A side-by-side comparison of the two languages is more involved that I intend to do here, my only point is that Python is very easy to start with and get productive with quickly.

For example, interacting with local text files can be involved with other languages. With Python, its simple:

file = open('output.txt', 'w')
file.write('Hello World')
file.close()

That’s it. Stupid simple.

My last project this year involved middleware servers, REST services, data tranformations of all sorts, multiple databases and data stores leveraging SQL and JSON, abstracted environment configurations to support dev ops in the larger environment, and more. Easy to manage in Python.

It’s a great language. Java is still number one, and the last I checked I think even C++ still dominates over Python on the list of world’s most in-use software languages.

But Python is the one to watch.

Python and SQL

Is it me?  Or is there a lot of buzz about Python lately?  Python is a great language for doing certain work quickly.  It supports a variety of software design approaches.  It is interpreted, and yet is object-oriented.  You can use it like an interactive calculator, and it comes with powerful math libraries.  It’s succinct – you can do a lot with fewer lines of code than is typical, but it can be used for large scale programming as well.  For these reasons and more, Python is growing in popularity, particularly in the fields of data analytics and data science.

It makes sense that it works well with SQL to provide data persistence. This blog post shows you how you can leverage existing SQL data stores with the power of Python.

It makes sense that it works well with SQL to provide data persistence. This blog post shows you how you can leverage existing SQL data stores with the power of Python.

Getting Ready

I downloaded and used the following software:

Python http://www.python.org 3.5.2 Popular software language!
SQLite http://sqlite.org 3.15.2 Embedded server-less SQL database
Oracle http://www.oracle.com 12c The world’s leading relational database management system
cx_Oracle http://cx-oracle.sourceforge.net/  5.2.1 Python extension module

I downloaded and installed Python and Oracle.  I also downloaded SQLite and cx_Oracle for use with Python.

Python and SQLite

SQLite is an embedded SQL tool.  It doesn’t have a separate server process, but is easily incorporated into applications. Here’s an example of Python code that uses SQLite, version 3:

import sqlite3
connection = sqlite3.connect("ships.db")
cursor = connection.cursor();
sql_statement = """CREATE TABLE ships
                  (    ship_id INTEGER
                     , ship_name TEXT);"""
cursor.execute(sql_statement)
sql_insert = """INSERT INTO ships VALUES(1, 'Codd One');"""
cursor.execute(sql_insert)
sql_insert = """INSERT INTO ships VALUES(2, 'Codd Two');"""
cursor.execute(sql_insert)
sql_insert = """INSERT INTO ships VALUES(3, 'Codd Three');"""
cursor.execute(sql_insert)
connection.commit()

The code above will successfully create a SQLite database file “ships.db”, then create table “ships” and then add three rows to it, and COMMIT the records.

In a subsequent script, you can query the same database.

import sqlite3
connection = sqlite3.connect("ships.db")
cursor = connection.cursor();
sql_statement = """SELECT ship_id, ship_name FROM ships;"""
cursor.execute(sql_statement)
print("fetchall:")
result = cursor.fetchall()
for r in result:
print(r)

The rows returned by the SELECT statement are processed within the “for” loop.  “Result” captures the result of the query, and “r” serves as a fetched value for each row.  In this case, each row represents an array of two values, and both values are displayed with the “print(r)” statement.

The output:

fetchall:
(1, 'Codd One')
(2, 'Codd Two')
(3, 'Codd Three')
>>>

Note:  the “>>>” symbol is the Python cursor, indicating the interactive system is awaiting the next instruction.

Python and Oracle

Now let’s use Python to send SQL statements to Oracle 12c. To establish the connection, we use the Python extension module “cx_Module”, available from SourceForge.net – see above for the links to all the software necessary to run these scripts.

Also – note that while SQL strings submitted directly to Oracle require semi-colons, SQL statements sent via cx_Oracle reject them.

In this example, we’ll do the same thing we did with SQLite, with one change: instead of breaking up the CREATE/INSERT and SELECT statements into two scripts, we’ll do it all in one script:

import cx_Oracle
connection = cx_Oracle.connect('username/password@localhost/orcl')
print("Oracle RDBMS version " + connection.version)

cursor = connection.cursor()

sql_statement = """DROP TABLE ships2"""
cursor.execute(sql_statement)

sql_statement = """CREATE TABLE ships2 
                   (   ship_id NUMBER
                     , ship_name VARCHAR2(20))"""
cursor.execute(sql_statement)

sql_insert = """INSERT INTO ships2 VALUES(1, 'Codd Crystal')"""
cursor.execute(sql_insert)
sql_insert = """INSERT INTO ships2 VALUES(2, 'Codd Elegance')"""
cursor.execute(sql_insert)
sql_insert = """INSERT INTO ships2 VALUES(3, 'Codd Champion')"""
cursor.execute(sql_insert)

connection.commit()

cursor.execute("SELECT ship_id, ship_name FROM ships2")
print("fetchall:")
result = cursor.fetchall()
for r in result:
print(r)

connection.close()

print("End of script, database connection closed.");

The output of this script is the same we saw earlier:

fetchall:
(1, 'Codd One')
(2, 'Codd Two')
(3, 'Codd Three')
>>>

Regardless of which database we use, the results are the same.

Closing Thoughts

In this blog post, we looked at how to use Python to execute SQL statements.  We created SQL objects, and sent data to the database, as well as queried data from the database.  We passed data to and from Python structures and set t he stage for any data manipulation we wish to do using these powerful tools.

Python is easy to use, and capable of performing complex math functions and data manipulation.  Using SQL to persist data for Python is an ideal combination for data analytics.

NOTE: This data and the accompanying scripts are available at my GitHub site: https://github.com/Skere9.

Number one again!

I was pleased to see that my SQL Expert book is yet again listed as a number one best seller this afternoon by Amazon.com’s book ranking system for two of the book’s categories:

  • Computers and Technology -> Databases and Big Data -> Oracle
  • Computers and Technology -> Certification -> Oracle

Trailing are excellent books in their own right, including many authored or co-authored by Oracle ACE Directors: a brand new Oracle Public Cloud book co-authored by Charles Kim, Mark Rittman‘s Business Intelligence book from Oracle Press, and Steve Feuerstein‘s legendary PL/SQL book.

I’m busy working on a new book from Oracle Press, more on that in the very near future – stay tuned! In the meantime, the 047 book makes a great holiday present for anyone in your life who wants to become a certified SQL Expert!

Below is the screenshot from the “Databases and Big Data” category:

Oracle SQL Expert Number One on the Amazon Best Selling Charts 11/29/2016 for its category.