02 Section 5 - File Handling and Storing Data Flashcards
What is the first thing you have to do when dealing with file handling?
Open the external file using an open command and assigning it to a variable
What is an open command in Read mode?
newFile = openRead(“newfile.txt”)
-sometimes you have to give the whole file path, not just the file name
What is an open command in Write mode?
newFile = openWrite(“newfile.txt”)
-sometimes you have to give the whole file path, not just the file name
What are the two modes you can open files in?
Read
Write
What is read mode for opening a file?
It allows you to read data from the external file into your program
What is write mode for opening a file?
It allows you to write data from your program to an external file
When a file is opened where does it start reading or writing from?
The beginning of the file
-as you read from or write to the file, the program keeps its place in the file
What is the last thing you should do when dealing with file handling?
You should close the file
-if you forget to close it then a file can remain locked and prevent others from editing it
What is the close command for file handling?
newFile.close()
How can you write to a file once it is opened?
newFile.writeLine()
-if the file already contains some text, then it will overwrite what is currently there
How can you read from a file once it is opened?
newFile.readLine()
-the program will always start reading from the first line of the external file
What is the file handling command which returns TRUE when the program is at the end of an external file?
newFile.endOfFile()
-used to signify when a program should stop reading a file
What do data bases order data into?
Fields (columns) and records(rows)
What do databases store data in?
Tables, made up of fields and records
What is a field?
A field is used to store a category
-a column of the table
What is a record?
A record uses the field to store details about a specific item
-a row of the table
What is the difference in data types between fields and records?
- all data in the same field has to have the same data type
- all data in the same record can have different data types
What does each table in a database have?
a primary key
What is a primary key?
A field which can uniquely identify any record in the table
-there is only one primary key field per data base table
What are the two types of database?
flat-file
relational
What is a flat-file database?
Databases that only have one table, which can be viewed by opening one data file
What is a relational database?
Databases that combine flat-file databases, the different tables are linked together by key fields
What does SQL stand for?
Structured query language
What is SQL?
A language that can create, update and query databases
-it consists of commands called statements
What is the first thing every database needs?
a table
What is the SQL statement for creating a table?
CREATE TABLE tablename (primarykeyfieldname DATATYPE PRIMARY KEY, fieldname2 DATATYPE, fieldname3 DATATYPE … );
What do you need to specify for each field in a table?
The data type
What are common SQL data types?
INTEGER REAL TEXT DATE BOOLEAN
What is the SQL statement for adding complete records to an empty table?
INSERT INTO tablename VALUES (data, data2, data3 …);
What is the SQL statement for adding incomplete records to an empty table?
INSERT INTO tablename (field, field2, field3 …) VALUES (data, data2, data3 …);
What is the SQL statement for updating a record?
UPDATE tablename SET field = data WHERE primarykeyfieldname = number;
When retrieving information from a database wheat are the key SQL statements?
SELECT
FROM;
What does a SELECT statement in SQL do?
Used to tell the database what information you want it to retieve
What does a FROM statement in SQL do?
Tells the database which tables to look in
What is the SQL statement for retrieving data from a database?
SELECT field, field2 …
FROM tablename;
What is the SQL wildcard for all the fields?
*
Why do you use a WHERE SQL statement?
To specify conditions that a record must satisfy before it is returned
What is the SQL statement for retrieving data from a database with specified conditions?
SELECT * FROM tablename
WHERE condition;
What conditions can be used with the WHERE SQL statement?
Comparison operators
Boolean operators - AND, OR
LIKE statements (to search for a pattern)
What are the SQL wildcards you can use?
- (to return all fields)
% (used in LIKE statements to represent any combination of letters or numbers)
What is the SQL statement for retrieving data from a database with specified conditions of partial information?
SELECT * FROM tablename
WHERE field LIKE “%parital information%”;
What is the SQL statement for retrieving data from a database in an order?
ORDER BY field ASC;
-sort records ACS (ascending) or DECS (descending) order