Essay Questions With Solutions: Answer T 010
Essay Questions With Solutions: Answer T 010
Underlying Storage
All the databases have fundamental persistent storage by using the file system. Examples of it are special operating
system files, normal operating system files and raw disk partitions.
User Interface
A command line tool is used for SQL commands and queries. This tool is provided by theaatabase
systems. Even
the GUI tools make use of command line clients or database client library so that the users are
provided with an
easy interface.
(iii) Databases
Thé RDBMS has the ability to manage various databases such as customer support, sales,
marketing etc at a time on
one server.The MYSQL is an example of server based RDBMS because it consists ofserver process
that is running
continuously.
(iv) Components
Databases consists of tables as storage abstractions. And every table consists of
rows and columns. A data base
schema can be defined as set of table definitions of columns and data types together.
The dmabases and tables can
be created and deleted as well. It is even possible to perform various
operations such as insertion, updation, deletion
etc on them.
(v) SQL
SQL provides database commands and queries to the database.
Various database commands in SQL are as follows,
Create Database
CREATE DATABASE SCHOOL;
Create
INT. NAME
Drop ATable
DROP TABLE
Insert a Row
INSERT INTO VALUESC21',
Delete g Row
DELETE FROM SCHOOL WHERE id - 2;
Relational database
(RDBMS)
Look for the SIA GROUP LOGO on,the TITLE COVER buys
Programming
UNIT-5 Database 5.7
•rypeObjects and Constructors
The python objects and native data objects are related with each other. When the
programmer sends any parameters to
database, they witl reach in the form of strings. need to bc converted into some other data types compatible
with the query.
DBAPI also needs to create the constructors that in turn create special objects. These objects can be easily
The type objects that are used for this purpose arc as follows, converted to
databaseobjects.
Type Object Description
Date from Ticks (ticks) It indicates the date object as per the given number
of seconds from epoch.
Timestamp(Yr, mo, dy, hr. min, sec) It indicates the object for timestamp value.
Time from ticks(ticks) It indicates the time object as per number of seconds
from epoch.
5. Relational Databases
The database systems that are accessible to interfaces in Python are as follows,
Informix MySQL
DB12
Interbase
MSSQL server
Ingres
ORM
ORM stand' managers, are various types Of database systems that enable users to maintain
to hame" poweq (bey need some KnowledgeOf SVC If the programmer can manipulate
thon than queries apd need database then ORM would be a best option.
and perform
"these are destgned in way that users can manipulate the Objects tasks, tables are
converted to Classes columns attributes and methods as database operations. The application can he
features and
to an ORM comples and even need more lines of code than using an adapter directly because
operations ('light be
they are.
OR A or work bett•lt' of users 'here arg two ORM's that are used more frequently.
, SQU Obje€t
SQL Atehemy
Other Python ORM's are Durus, POO. Oejavu. PyD(VPy002. Qi,imc. Forget SQL etc. Certain web based systems can
their own ORM component webware middle kit and Django's database API.
Example
SOLAlchemyORM
import os
exn eng.connection()
except _mysql_excepuons.OperationalError, e:
eng t ••
except _mysqieexcepåonsOperatiooalErtot, e:
DATABASE %
eng I.eomniit()
esn • eng.eonnection()
eng. autoload-True)
users Tablefilsers'.
e:
except exceptions.SQLError,
eng, String(8)). Column('uid'. Integer). Column('prid'. Integer), redefine—True)
users •
self.eng •neng
self.cxn cxn
self.usets •e users
defcreate(self):
usets self.users
users.drop()
e:
except exceptions.SQLError,
users.create()
def insert(selD:
return
def update(selt):
users self.users
fr rrange( I
to rrange(l,5)
return fr, to, \
users self.users
rm rrange(l.S)
return tm, \
def dbDump(selO:
res
attr):
def finish(seli):
self.cxn.commit()
self.eng.commit()
def main():
orm. insert()
orm.dbDump()
orm.dbDump()
orm.dbDump()
Dropping users table'
SQLObjeet ORM
import
from random- import randrange rrange
from sqlobjectimr»rt •
from ushume_db import NAMES, randName
DBNAME = 'test'
COLSIZ = 10
class MySQLObject(object):
import MySQLdb
import _mysql_exceptions
url % DBNAME
while Trues.
cxn connectionForURI(urI)
sqlhub.processConnection = cxn
#cxn.debug Tn.E
class Users(SQLObjectY.
class sqlmeta:
fromDatabase True
login StringCol(length—8)
—IntCol()
—IntCol()
clus Users(SQLObject):
uid IntCol()
prid •eIntCol()
e:
_mysql_exceptions.OperationalError.
except
exnl sqlhub.processConnection—
% DBNAME)
cxnl .queryC'CREATEDATABASE
% DBNAME)
cxnl ALL ON %s.• TO
cxn I .elose()
self.users Users
self.cxn —cxn
Users self.users
Users.dropTable(True)
Users.createTable()
def insert(selO:
uid, rrange(l,5)J)))
def update(selt):
fr rrange( I ,5)
to —rrange(l,5)
users = self.users.selectBy(prid=fr)
user.prid = to
def delete(self):
rm = rrange(l,5)
users = self.users.selectBy(prid=rm)
Look for the SIA GROUP LOGO on the TITLE COVER beforeyoubuye
user.dgstroySelf()
def
print % 'PROF.IÄCOLSIZ))
for usr in self.users.select():
def main():
orm.create()
orm.insert()
orm.dbDump()
orm.dbDump()
orm.dbDump()
orm.drop()
orm.finish()
if name main
main()
depicted follow,
The most commeutiy used relatnf mcxlule•sand datat.ses that work in database programming
MYSQI. PypgSQt.
o.dfly Psycopg
PypgSQL
Psyeopg 2 PostgreSQI„
MYSQL.python
SQL-ite adodbapi
APSW sybase
sqlite3 Sybase
pysqlite oracle
sapdb Dcoracle2
sdb ex oracle
MaxDB(SAD) ingres DB!
KlnterbasDB ORMS
pymssql ingmod
SQLserver SQLAlchemy