Python – PyODBC – Microsoft Access : Simple script


Here’s a simple python script showing how to access MDB (Microsoft Access) database

import os
import pyodbc

dataFile = "Northwind.mdb"
databaseFile  = os.getcwd() + "\\" + dataFile
connectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=%s" % databaseFile
dbConnection   = pyodbc.connect(connectionString)
cursor = dbConnection.cursor()
cursor.execute("select top 5 * from Suppliers")
rows = cursor.fetchall()
for row in rows:
    print row.CompanyName

take a look at the script below to get column names, column type and width

import os
import pyodbc

dataFile = "Northwind.mdb"
databaseFile  = os.getcwd() + "\\" + dataFile
connectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=%s" % databaseFile
dbConnection   = pyodbc.connect(connectionString)
cursor = dbConnection.cursor()

for row in cursor.columns(table='Suppliers'):
    print "Field name: " + str(row.column_name)
    print "Type: " + str(row.type_name)
    print "Width: " + str(row.column_size)

Casperjs – Couldn’t find nor compute phantom.casperPath, exiting


I just installed phantomjs v2.0 on a Windows box, add its location to its path, download casperjs v1.0.4, extract to root folder on C: drive, rename the folder to casperjs, add casperjs\batchbin to its path (not casperjs\bin as suggested in its documentation), invoking casperjs –version on the command line, but then getting this error message

Couldn’t find nor compute phantom.casperPath, exiting

googling for a minutes, I got the solution here https://github.com/n1k0/casperjs/issues/1150

just add these 4 lines code into casperjs\bin\bootstrap.js file


var system = require('system');
var argsdeprecated = system.args;
argsdeprecated.shift();
phantom.args = argsdeprecated;

Adminer – Set Number of Rows to Display


I’ve ever wrote how to set this on PhpMyAdmin, now I want to do it on Adminer. I want Adminer to show 200 records when I select a table. I’ve try it using Adminer v4.1.0 and v4.2.0 both for MySQL english only.

I just search the string “selectLimitProcess(){” with no quote off course and then replace its default number from 50 to 200, you can use any number you want.

Excel VBA – ZIP Compress a file


I just got a need to compress a file through Excel VBA, here’s what I have found so far from Google.
You will need adding reference to Microsoft Scripting Runtime and Microsoft Shell Controls and Automation (by clicking menu Tools > Reference)


Option Explicit
Option Base 0

Private Declare Sub Sleep Lib “kernel32” (ByVal dwMiliseconds As Long)

Public Sub MakeZip(zipPath As String, filePath As String)
MakeEmptyZip zipPath
AddFile zipPath, filePath
End Sub

Private Sub AddFile(zipPath As String, filePath As String)
Dim sh As Shell32.Shell, fdr As Shell32.Folder, cntItems As Integer ‘cnt = Count
Set sh = CreateObject(“Shell.Application”)
Set fdr = sh.Namespace(zipPath)
cntItems = fdr.Items.Count
fdr.CopyHere filePath, 4 + 16 + 1024
Do
Sleep 1000
Loop Until cntItems < fdr.Items.Count
Set fdr = Nothing
Set sh = Nothing
End Sub

Private Sub MakeEmptyZip(zipPath As String)
Dim fso As Scripting.FileSystemObject
Set fso = CreateObject(“Scripting.FileSystemObject”)
If fso.FileExists(zipPath) Then
fso.DeleteFile zipPath
End If
fso.CreateTextFile(zipPath).Write “PK” & Chr(5) & Chr(6) & String(18, Chr(0))
Set fso = Nothing
End Sub

Private Sub cmdCompress_Click()
Dim sourcePath As String
Dim zippedPath As String

Dim sourceBaseName As String
Dim zippedBaseName As String

Dim sourceFullPath As String
Dim zippedFullPath As String

sourcePath = “C:\Users\Remo\Downloads\”
zippedPath = “C:\Users\Remo\Downloads\”

sourceBaseName = “DATA.MDB”
zippedBaseName = “DATA_Compressed.zip”

sourceFullPath = sourcePath + sourceBaseName
zippedFullPath = zippedPath + zippedBase

Call MakeZip(zippedFullPath, sourceFullPath)

MsgBox (“File ” + sourceBaseName + ” successfully compressed into ” + zippedBaseName)
End Sub