Posts

Showing posts from May, 2011

sed awk perl python

sed - when you need to do simple text transforms on files.
awk - when you only need simple formatting and summarization or transformation of data.
perl - for almost any task, but especially when the task needs complex regular expressions.
python - for the same tasks that you could use Perl for.

ACID in EJB

Every transaction has a beginning and an end. The process of marking the transaction boundaries is known as transaction demarcation. Transactions either commit or roll back to their initial stage. In EJB, a transaction must pass the ACID test, i.e., it must meet the following requirements:


Atomicity: A transaction is an atomic unit of work. This means that in order to be in a transaction, a group of activities should succeed, or all of them should fail. If a transaction is interrupted, all previous steps within that transaction are undone. For example, while withdrawing money from an ATM, the account balance of the cardholder is checked, the money is withdrawn, and the balance is deducted. If any of these steps fail, the transaction should be rolled back as if nothing happened.




Consistency: This property of transaction refers to the behavior of data after a transaction is completed. Whether a transaction commits or rolls back, it must leave the data in a consistent state. When money is …

Sample Pathon Script to deal with MySQL

yum install mysql-python 
 to install MySQLdb for Python in CentOS or Fedora.

You use "%s" even you insert a float to a table
Following is the sample script:

#!/usr/bin/python

import MySQLdb

conn = MySQLdb.connect (host = "host",
user = "us",
passwd = "pass",
db = "yourDB")
cursor = conn.cursor (MySQLdb.cursors.DictCursor )
cursor.execute ("SELECT * from yourTable")

rows = cursor.fetchall ()
for row in rows:
print (row["name"], row["description"], row["description2"], row["category"], row["price"])
cursor.execute (' insert into anotherTable (companyid, name, description, description2, category, price) values (6800, %s, %s, %s, %s, %s)', (row["name"], row["description"], row["description2"], row["category"], row["price"]))

print "number of all: %d" % cursor.rowcount

cursor.close ()
conn.commit()
conn.close ()