Visual Basic: An Object Oriented Approach 9 - Persistence.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

Chapter 10: Designing Databases
Databases. A database program can be used to:  sort a file into a different order  Maintain contact with clients  search through the records for a.
Database System Concepts and Architecture
CSM18 FilesDr Terry Hinton1 VB - Persistence in software Information entered into a program is volatile Can switch computer off Power can be removed accidentally.
Data Models There are 3 parts to a GIS: GUI Tools
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Database Software File Management Systems Database Management Systems.
Database Management: Getting Data Together Chapter 14.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
2 Systems Architecture, Fifth Edition Chapter Goals Describe numbering systems and their use in data representation Compare and contrast various data.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Operating Systems.
WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC BY V. V. SUBRAHMANYAM.
Systems Software Operating Systems.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
The Operating System. Operating Systems (F) What you need to know about –operating system as a program; –directory/folder.
Object Oriented Databases by Adam Stevenson. Object Databases Became commercially popular in mid 1990’s Became commercially popular in mid 1990’s You.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Systems Software & Operating systems
ASP.NET Programming with C# and SQL Server First Edition
Interacting With Data Databases.
Topics Introduction Hardware and Software How Computers Store Data
Standard Grade Computing System Software & Operating Systems.
State Management. What is State management Why State management ViewState QueryString Cookies.
Computers Data Representation Chapter 3, SA. Data Representation and Processing Data and information processors must be able to: Recognize external data.
File Systems Long-term Information Storage Store large amounts of information Information must survive the termination of the process using it Multiple.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Scalable Web Server on Heterogeneous Cluster CHEN Ge.
File Structures Foundations of Computer Science  Cengage Learning.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Operating Systems COMP 4850/CISG 5550 File Systems Files Dr. James Money.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
Chapter 4c, Database H Definition H Structure H Parts H Types.
INFORMATION MANAGEMENT Unit 2 SO 4 Explain the advantages of using a database approach compared to using traditional file processing; Advantages including.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
SYS364 Database Design Continued. Database Design Definitions Initial ERD’s Normalization of data Final ERD’s Database Management Database Models File.
Database Management Systems (DBMS)
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
Files Tutor: You will need ….
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
( ) 1 Chapter # 8 How Data is stored DATABASE.
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Chapter 3 Data Representation
Topics Introduction Hardware and Software How Computers Store Data
Database Database is a large collection of related data that can be stored, generally describes activities of an organization. An organised collection.
Chapter 1: Introduction to Computers and Programming
What is a Database and Why Use One?
MSIS 670: Object-Oriented Software Engineering
Topics Introduction Hardware and Software How Computers Store Data
Chapter 10 ADO.
Introduction to Computer Programming
Introduction to Data Structure
Database management systems
Presentation transcript:

Visual Basic: An Object Oriented Approach 9 - Persistence

Persistence in software Information entered into a program is volatile Can switch computer off Power can be removed accidentally Power-cuts System could crash We need to make data persist beyond a single run of a program

Files  File - an orderly line  In admin, a file is used to keep like items together in an order  In a computer, a file is a storage mechanism, usually associated with long-term storage on magnetic media  A computer file has an order  items are written to the file in strict sequence  items are read from the file in the same sequence

Computer file mechanisms  In a computer, files are handled by the operating system  Provides facilities to open, read items from, write items to and close files  to maintain a link between a program and an open file, the O/S assigns a file handle; a number by which the file can be identified  Programs use operating system services  Normally facilities are added to programming languages to access these services

Creating a file  To create a computer file  Ask the O/S for a file handle  Open the file for write access  Send data item variables to the file in some order  Close the file  The order of the file is defined at the point of creation  Care required to prevent file errors due to upset sequence

Code to create a file Sub CreateFile( ) Dim f As Integer ‘ File handle Dim aName As String Dim aNumber As Integer f = FreeFile Open “MyFile.dat” For Output As #f aName = InputBox(“Name?”) Write #f, aName aNumber = InputBox(“Number?”) Write #f, aNumber Close #f End Sub Sub CreateFile( ) Dim f As Integer ‘ File handle Dim aName As String Dim aNumber As Integer f = FreeFile Open “MyFile.dat” For Output As #f aName = InputBox(“Name?”) Write #f, aName aNumber = InputBox(“Number?”) Write #f, aNumber Close #f End Sub Ask for handle Open File Send data Close file

Retrieving data from a file  To retrieve data from a file  Ask the O/S for a file handle  Open the file for read access  Read data items from the file - they will be in the same order  Close the file  File problems generally due to sequence problem  e.g. program reads a string when expecting a number

Code to retrieve data from a file Sub ReadFile( ) Dim f As Integer ‘ File handle Dim name As String Dim number As Integer f = FreeFile Open “MyFile.dat” For Input As #f Input #f, name MsgBox name Input #f, number MsgBox number Close #f End Sub Sub ReadFile( ) Dim f As Integer ‘ File handle Dim name As String Dim number As Integer f = FreeFile Open “MyFile.dat” For Input As #f Input #f, name MsgBox name Input #f, number MsgBox number Close #f End Sub Ask for handle Open File Read data Close file

Types of file  Files can be organised in a number of ways  Tabular  Character based text  Text with line-breaks  Binary (sequential)  Binary (Random access)  File organisation is determined by...  the program code that writes the file  the variable types stored  decisions made by the programmer in the interests of efficiency and ease of use

File formats “Fred Bloggs”, “1 High Street”, £200 “Jane Smith”, “55 Glen Road”, £28.55 The key feature of this file is that it is composed of a continu ous sequence of text characters with no format beyond the la nguage used. Strictly, it should be seen as one long line of te xt characters. This type of file is distinguished by the use of line breaks (special, non-printing characters) to preserve the format of the text. Each line ends with a line-break and so need not be a fixed length. Tabular Text with Line breaks Character

File formats II E9 26 0D DB B CD 21 F6 D2 F6 C F6 C2 02 C3 8B C A3 D4 13 5B 89 1E D6 13 F8 FF E3 8B 26 D4 13 8B 1E D6 13 F9 FF E B F0 AC 0A C0 74 1E 3C 0A 74 F7 3C 0D A D0 B4 02 CD 21 EB EB B2 0D B4 02 CD 21 B2 0A B4 02 CD 21 EB DD 5E 5A C BB D2 13 B9 0A D2 F7 F1 80 C2 30 4B B C0 75 F2 8B C3 E8 BA FF 5A 59 5B C3 50 B8 D8 13 E8 AF FF 58 E8 AB FF B E8 A5 FF C3 E8 EB FF B4 4C CD E CA 13 FF B E F B8 6B 16 F7 06 7A E E8 7E FF A1 7A E 00 3D B2 09 B4 02 CD 21 EB 1E B E8 65 FF EB B8 5D 16 E8 5C FF 58 E8 58 FF B E8 52 FF C6 06 CA 13 FF C3 0B ED F7 06 7A F7 06 7A F8 C3 F9 C3 A0 C9 13 Binary (this is Hexadecimal which is a representation of binary) Random access is similar, but each record is the same number of characters long

Files and objects We send objects to a file by serializing them The data in each object is written out as a sequence of values, either in binary of character form The class is responsible for sending and retrieving object data Consider a serialised file of objects to be a stream Can also use streams to transmit and receive objects over a number of different media

Streams Provide an object with Save and Load methods By keeping the code within the class, objects manage serialization with no help from client programs Complex objects (e.g. structured hierarchies) can manage themselves hierarchically

Sending an object hierarchy to a stream ‘ Save to Stream pseudo code… Write each member variable to the stream Write the number of child objects to the stream For each child object Repeat the process Next ‘ Save to Stream pseudo code… Write each member variable to the stream Write the number of child objects to the stream For each child object Repeat the process Next Recursive nature of this means a complex hierarchy does not require complex code Only ever need to deal with this object and its direct children (which deals with itself and its children etc.) The count of child objects is the key to being able to retrieve the while hierarchy from the stream

Retrieving an object hierarchy ‘ Load from Stream pseudo code… Read each member variable from the stream Read the number of child objects from the stream For index From 1 To Number of children Create a new child object Get it to retrieve itself from the stream Next ‘ Load from Stream pseudo code… Read each member variable from the stream Read the number of child objects from the stream For index From 1 To Number of children Create a new child object Get it to retrieve itself from the stream Next More complex that sending hierarchy to stream Need to create new child objects before each can read data from the stream Need to build up hierarchy

Objects and Databases Streams of objects have an inherent problem Need to send and retrieve the whole hierarchy No chance of reading one or two items back OK for a few hundred or thousand items Not possible for millions In this case, a database provides the solution Structured random access Fast retrieval of objects and sets of objects

Pure object databases Transparent in operation Linked tightly to the language and the operating system Automatic retrieval of objects as needed Try to access an object currently not in memory, and it will be fetched automatically Tends to be domain specific CAD systems Large structured inventories

Relational object databases Make use of existing relational database technology Common, cheap, well understood Can fit into any domain that works with a database Legacy systems Common computer storage mechanisms Data, Mail, Documents etc.

Relational object modelling One table per class Relationships between records map relationships between objects Class methods can hide relational database layer Automatically fetch objects as references to them are made Automatically flush objects to database on destruction Coding can become awkward and complex Rewards in flexibility and legacy compatibility

Tiered system models Three (or more) tiers Presentation Business Data access

Tiers and responsibilities Presentation layer Handles user-interactions Connects to business logic only Business logic layer Enforces rules on use of data and access to it Models the way the business uses information Data access layer Enforces data security and integrity Maintains connections to various data sources and presents them in a homogenous way to the business layer

Visual Basic data access ActiveX Data Objects (ADO) (Bizarrely, Microsoft says the X is silent) A simple, uniform layer of services for accessing almost any type of structured data Relational databases (various products) Mail servers Flat-file data from spreadsheets, old style databases Filing system resources

ADO Object Model Connection class Creates and maintains links to data sources Recordset class Presents data as tables of records Using these two classes, possible to work with any database Connection opens and closes links and sends Commands to database engine Recordset allows new records to be created, records manipulated, records deleted