Database Access and Management with usage of the

0 downloads 0 Views 486KB Size Report
5 View of SQL activity edition window. Despite the fact that simple database querying is the mostly performed action in a database, it isn't the only task realized ...
Database Access and Management with usage of the MOODLE platform Database in www – the MOODLE e-learning platform as a flexible instrument for teaching (publishing) databases’ (computer-aided database/subject education)

K. Harężlak1 and A. Werner1 1

Silesian University of Technology, Gliwice, Poland, {katarzyna.harezlak, aleksandra.werner}@polsl.pl

Abstract. The possibility of using MOODLE e-learning platform as an environment for teaching database issues, concerning database objects and users creating, analysis and management of a transaction has been analyzed in the paper. All of the needed extensions were made using php scripts and were tested in the chosen database servers: MySQL, SQL Server and Oracle DBMS. Results of these tests were satisfactory, confirming preliminary assumptions.

1 Introduction The usage of e-learning platforms has become more and more popular throughout the recent years. They allow teachers to build effective online courses and to manage learning on the web. Owing to them, faster knowledge access and learning costs reduction have been achieved. There are many mechanisms of such platforms, allowing theory presentation and verification of the knowledge gained by trainees, in a simple way [Bylina at al. 2008, Gumińska and Madejski 2007]. Nevertheless, in some knowledge branches training plays much more important role than theory. Especially such database issues, as: database designing, querying and management, require intensive practice. Analyzing various database problems, SQL (Structured Query Language) query training seems to be the most important challenge in e-learning database knowledge teaching. If the necessity of practicing in real database environment – preferably environment, in which course beneficiaries will work in future – is taken into account, this challenge becomes a critical in a database e-learning. As far as fundamentals of SQL are concerned, they can be presented on an elearning platform in simple html webs, while quizzes, lessons or chats might be used for knowledge verification. But still there is a problem how to provide students with online connection to a database server in order to practise SQL. In

many cases, the only applicable solution is requesting students to install chosen database server in their private computers, creating a database and load data, available on html page. Actually, the guidelines for these tasks can be provided via e–learning platform, but configuration of database environment must be performed by students on their own. If we take into consideration that a group of course participants has just started studying database problems, this process can be too difficult for them. In [Harezlak and Werner 2010] an innovative approach to tackling this problem was proposed, where several students databases were replaced by one database managed by a teacher (Fig. 1). Besides, the new activity mechanism – SQL – of elearning platform was introduced, which made a database interactive querying possible.

Fig. 1 The idea of the implemented architecture in an e-learning environment

The opportunity of connecting to a database server via software for collaborative learning, removes mentioned inconveniences – it means: exempt students from the obligation of database environment self-configuration. The next advantage is the centralization of the process of preparing a database for various tasks realization. If a teacher has to change database schema or structure, it can be done in one, centralized database and it will not have to be immediately propagated to students local databases. For new database activities implementation, the MOODLE e-learning platform was chosen. Extension of its functionality was possible owing to open-source software and specific modules structure, and was resolved by creating and configuring a new component, very similar to already existing ones (in [Harezlak and Werner 2010] the composition of each built-in MOODLE module was described in detail). Because each module (for example: quiz, glossary, forum) has its own folder containing collections of analogous files, the process of preparing a new ac-

tivity in practice involves the creation of a a new folder, named the same as the title of new activity, in which all needed files are collected. The most important files, in context of the research, are: mod_form.php and view.php, which are responsible for displaying – respectively – form to teacher, where task conditions are defined and the window for students, which enables them to execute designed task.

2 SQL Modules Taking the SQL subtypes and the database e-learning needs into account, new activities – such, as: SQL DCL, SQL DDL and SQL DML were required to be implemented. Additionally, the SQL ACID and SQL TSQL were also realized, in order to allow more advanced users to practice more complex database issues (Fig. 2).

Fig. 2 List of activities connected with a given course

For this purpose, a set of new modules, destined for every task specified above, was coded. Although they differ in functionality and require separate programming, all of them define the parameters for database server communication in mod_form.php file.

Fig. 3 List of available database servers

Because of the fact that it was assumed that central database engine may vary depending on the teacher needs (Fig. 3), the first step of changing the MOODLE source was activating needed PHP language extensions, by clicking on WAMP server tray icon – Fig. 4.

Fig. 4 List of accessible PHP extensions

The subsequent stage was connected with implementing desired functionality in PHP scripts, simultaneously with taking into account the specific characteristics of the chosen database engines (for example database backup and restore methods).

2.1 SQL First

module,

SQL,

was

designed

to

provide

an

environment

for

SELECT…FROM…WHERE… query realization. As a main database server MySQL

– one of components cooperating with the MOODLE platform – was chosen [Welling and Thomson 2005], but proposed solutions were also tested in other database servers like Oracle, MS SQL Server and IBM DB2. In order to enable connection to Database Management System (DBMS), a few teacher-depend parameters (database host, name, user and password) had to be set (Fig. 5). The methods of connection establishing and result set displaying were presented in details in the paper [Harezlak and Werner 2010].

Fig. 5 View of SQL activity edition window

Despite the fact that simple database querying is the mostly performed action in a database, it isn’t the only task realized in a database [Garcia-Molina and al. 2003]. To have a possibility of data querying, first of all, tables, which will store records of data, must be created. Subsequently, these tables must be filled with records. Besides, very often database users face the problem of records modification and databases protection against software and hardware failure, by backup execution. Analyzing the limitations, resulting from the form of training, an underlying inconvenience was found, directly associated with the nature of the tasks performed by students. If the number of participants of the course is not settled beforehand, executing the commands in the same database can lead to some undesirable effects. Among them we can enumerate: the possibility of objects names duplication and uncontrolled objects removal, deadlock, hindering or making given tasks impossible to perform. To avoid such problems, the mechanisms for creation a copy of a processing database (Source Database) for every student were implemented. The name of the database created for a particular user is constructed dynamically according to the pattern: SourceDatabaseName + UserId + ModuleId. Student’s source database is specified in Source Database Path and Database Path parameters of teacher’s window. This strategy provides a unique database naming and allows unlimited number of students to perform an SQL command. So, each course member works on his own copy of the source database.

Additionally, owing to this, the teacher obtains control over the activities of a particular student. Trainer gains a possibility for a detailed analysis of the tasks performed by a student or for evaluation. Implementation of the source database duplication assumes, that after clicking a task of a given module, only its content and button are initially visible. Choosing this element results in starting of database creation process, that consists of the template database backup and retrieving the contents of its copy to the appropriate, new student’s database. This is possible by an activity window configuration, where teacher fills the fields of database path, server, name and user name with enough privileges to connect to the server. These information are forwarded to the php code performing the task. Right after that, the form for SQL query performing appears ( Create Database button became inactive) – Fig. 6.

Fig. 6 Final view of the DCL task realization window

Presented mechanisms were used in every created module, described later. The possibility of verification of the correctness of the tasks performed by student was achieved through creation of additional tables on the server. They store such information as: module identifier, sent query content, needed timestamps, whether a copy of the module has already been executed, etc. The names of these tables (Fig. 7) were constructed in the following way: – for commands being the tasks solutions:  DatabasePrefix_SQLSubsetName,  DatabasePrefix_SQLSubsetName_answare, –

for source database copies created by students:  DatabasePrefix_SQLSubsetName_load,

where:

 DatabasePrefix means the database prefix defined in the MOODLE configuration file config.php,  SQLSubsetName is a name of the given module.

Fig. 7 List of supplementary tables stored in the database of the MOODLE platform

For example, after pressing the Create Database button in the DML module window, the table DatabasePrefix_DML_load is updated by the following code in the file view.php: switch ($_POST['bsubmitt']){ case 'Create Database': $dataobject = new Stdclass; $dataobject->who_load_db=$USER->id; $dataobject->is_db_load = 1; $dataobject->module_id=$dml->id; $dataobject->db_name=$dml->dbname; insert_record('dml_load', $dataobject); }

These settings mean that a database copy was created (value 1 in field is_db_load) for the module (field module_id) by the user, whose ID is stored in the who_load_db field.

In addition, the function, checking whether the user has already created his own copy of the database in the appropriate module, was written. If a query in the general form: $query = 'SELECT * FROM DatabasePrefix_SQLSubsetName_load WHERE who_load_db = '.$USER->id. ' and modul_id = '.$o;

returns a row of data, pressing the Create Database does not take any action. Such protection ensures that creating private copy of a database for each participant is performed only once. This applies for the entire set of queries using the given database source.

2.2 SQL DDL and SQL DML modules Each of the designed database e-course modules corresponds to specific group of database issues and requires knowledge of selected category of SQL statements. In particular, module M04 (Fig. 8) explains the basics of the Data Definition Language used to build and modify the structure of tables and other objects in the database.

Fig. 8 Link to DDL module in designed database course

Process of the DDL module creation was influenced by a modular construction of the e-learning platform. It consisted of creating a new DDL folder, with its standard components, and placing it in the mod subfolder of the MOODLE project home directory. Next, the mod_form.php and view.php files were adapted to needed functionality. In the first of the mentioned files, the definitions of the fields that allow the teacher to enter the relevant parameters of the database during the activity edition were specified. The code below: $mform =& $this->_form; // Adding the "general" fieldset, where all the common settings are showed $mform->addElement('header', 'general', get_string('general', 'form')); … // Adding the rest of ddl settings … $mform->addElement('text','mysqldump',get_string('mysqldump','ddl')); $mform->setType('mysqldump', PARAM_TEXT); $mform->addRule('mysqldump', null, 'required', null, 'client'); $mform->addRule('mysqldump',get_string('maximumchars',255),'maxlength',255,'client'); $mform->addElement('text','mysql',get_string('mysql','ddl')); $mform->setType('mysql', PARAM_TEXT); $mform->addRule('mysql', null, 'required', null, 'client'); $mform->addRule('mysql', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addElement('text','dbname',get_string('dbname','ddl')); $mform->addElement('text','dblogin',get_string('dblogin','ddl')); $mform->addElement('text','dbpassword',get_string('dbpass','ddl')); …

corresponds to the teacher’s form presented on Fig. 9.

Fig. 9 List of activities connected with a given course

The second file, view.php, contains code that: – allows to perform DDL commands, – manages the content of the window that student executes his tasks through. The designed module was used – inter alia – to examine the relationships of the primary key. These include the following steps: 1. Create table: CREATE TABLE Employee (emp_no int, emp_name text);

2. Define primary key in a table: ALTER TABLE Employee ADD PRIMARY KEY (emp_no);

3. Insert 3 rows into a table: INSERT INTO Employee VALUES (1,'Wolf'), (2,'Barry'), (3,'Smith');

4. Insert 3 subsequent rows into a table, but one of the key column value should be repeated (should be the same as the value previously specified): INSERT INTO Employee VALUES (4,‘Jackstraw’), (5,‘Terry’), (3,‘Kelly’);

Message shown in the Fig. 10 allows to state that the task is not performed correctly, because it violated the integrity constraints. Besides, analysis of the results returned by the query SELECT * FROM Employee will show, that all changes made in point 4 have been rolled back since they were treated as a one indivisible unit – e.g. a transaction.

Fig. 10 Error report

2.3 SQL DCL module Like other modules, SQL DCL activity has its own, untypical – for developed components – functionality, that had to be implemented there. The reason for this is that the group of SQL keywords, practised in the module, handle the authorization aspects of data and permits the user to control who has access to see or manipulate data within the database. So, because of the fact that every user in the database is especially allowed to access specific data objects or to perform some of system level activities, there should be a possibility to check whether grantee has really gained privileges (or group of privileges). For example, after creating a new user and granting him chosen object privilege, students should have the chance to connect to the database as a new user and try to execute an operation on a granted object. Thus, in DCL module, the Login and Password text areas appear in students’ window, in order to make the verification, whether the effect of written commands is in accordance with student’s supposition, possible (Fig. 11).

Fig. 11 The final view of the DCL task realization window

For this purpose the button Change User was coded in view.php file:

and special function logOn was implemented in a script: function logOn(txtarea1,txtarea2) { var login=(txtarea1.value); var pass=(txtarea2.value); window.location.href = "view.php?id="+firstVar+"&login="+login+"&pass="+pass; }

After re-logging, an empty area that allows entering SQL commands is displayed and, after executing a DCL statement, result or appropriate message is shown (Fig. 12).

Fig. 12 Exemplary error message

3 Transaction realization Using the database, it must be remembered that in many cases, commands sent to it must be treated as a transaction, characterized by the following properties: Atomicity, Consistency, Isolation, Durability (ACID). As a part of their training, students are acquainted with knowledge how to define a scope of transaction and how the database server ensures its properties. Research in this field included the solution of two problems. The first one concerned the evaluation of the possibilities and methods of the SQL commands execution with usage of a transaction. The second was related to a schedule of the transaction realization using the locks and defined levels of isolation. A. Transaction atomicity To meet the demands of the first issue, the environment was prepared to test the ACID properties of transactions. For this purpose a series of experiments was performed. For example, the command to transfer the fees for studies from student’s account (account_ID=100 and bank_ID =1) to the account of the university (account_ID=200 and bank_ID=2) was analyzed. Two different situations were examined:

1. Commitment of the transaction. BEGIN TRANSACTION; UPDATE account SET stan = stan – 500 WHERE account_ID = 100 AND bank_ID = 1; UPDATE account SET stan = stan+100 WHERE account_ID = 200 AND bank_ID = 2; COMMIT;

2. The transaction roll backing. BEGIN TRANSACTION; UPDATE account SET stan = stan – 500 WHERE account_ID = 100 AND bank_ID = 1; UPDATE account SET stan = stan+100 WHERE account_ID = 200 AND bank_ID = 2; ROLLBACK;

Experiments carried out on the MOODLE platform, in the new ACID module, confirm the possibility of explicit definition of the transaction scope by the START/BEGIN TRANSACTION command and the COMMIT or ROLLBACK. This allows demonstrating students the existence of transaction atomicity property. The second option for defining the transaction scope is to use PHP script commands to start and to end the transactions implicitly. [Swan 2009]. In order to do that, the code of view.php file should be supplemented with appropriate instructions: create a connection variable; if (connection established){ Create the variable that holds SQL statements; Start a transaction; Parse the statements in the context of a database connection; Execute the statements; Recognize mistake and rollback changes while (there are rows in the result set){ get the number of columns used in SQL statement; for ($i is less than number of columns){ return column value for fetched row; } } } else print an error message and exit the program; Free up the resources used to perform the query; End the transaction; Close the database connection;

It should be noted that commands realized without explicit definition of the transaction can be treated as an independent one [Harezlak and Werner 2010].

This is tantamount to a default setting of AUTOCOMMIT option during a connection to the database. This results in an automatic commission of each DML command by the server. Taking the possible models of the database engines activity into consideration, the tests of changing these settings by the command SET AUTOCOMMIT OFF were examined as well. B. Isolation levels – consistency and isolation During works on the MOODLE extension, much attention was paid to the issues related to the organization of access rights to resources (command LOCK/UNLOCK) and the subsequent transaction properties – consistency, and isolation.

Fig. 13 Window of a task realization in SQL TSQL module

The need to ensure that commands of two concurrent transactions operating on the same data sets, resulting in equipping the developed module with two windows. Owing to this, the possibility of transactions execution in two concurrent sessions was achieved (Fig. 13). During tasks realization, students are familiarized with the names of the isolation levels and syntax of commands setting. This solution also allows to observe the effects of the undesirable phenomena accompanying the particular isolation level. Among these there can be found: dirty read or deadlock. The example of such a task is shown in the Fig. 13. C. Durability effect Another challenge to be faced was to demonstrate and clarify the mechanisms for ensuring durability of transactions. The set of objects used by a server to protect a database from system failure consists of databases copies and transaction logs. Therefore, in the ACID module the functionality of a database backup via an interactive window was implemented. This copy is subsequently used for restoring corrupted database.

At the present stage of system development, when working with MySQL server, students have two possibilities for database backup. One of them allows remembering the data stored in the table, in an external file, by executing the command SELECT * INTO OUTFILE 'OutputFileName' FROM TableName. The second one gives the possibility of backup all the tables with their data, by pressing Create Backup.

Fig. 14 Parameters needed for students’ database backup

This button reads the needed parameters from the form displayed by mod_form.php file (Fig. 14) and calls mysqldump program: $rev = system($dml->mysqldump. ' -u '.$CFG->dbuser. ' -p'.$CFG->dbpass. ' '.$dml->dbname. '>'.$dml>path_for_user_db1.'temp.sql');

In other database system the DDL command, like BACKUP DATABASE, can be used instead.

4 Database programming Participants, who learned the rules of SQL queries constructing and acquired the abilities connected with data manipulation are ready to get to know the aim and the rules of database programming. Each database server is equipped with its own programming language, mainly based on SQL commands, enhanced with variables declaration, commands managing the flow or defining the loops. These languages are used to implement database stored procedures and triggers, both of which play a crucial role in databases. Stored procedures allow to place the business logic on the server and they are a very important part of database protection, hiding its structure from the user. The second of the programmed object types, triggers, enable an active database reaction to the changes performed within its records.

Utility of the discussed objects decided about introducing to the platform a new module, facilitating their study. Owing to the fact that database procedures are an object of a particular database, in this module there were used mechanisms, developed beforehand, separating working areas of particular course participants. Additionally, a requirement concerning student’s preparation for the tasks he is to face was introduced. This is the result of the fact that to be able to design and implement database procedures properly, one needs to be familiar with SQL, or even DDL, commands. Therefore, if a student starts performing the tasks from the Database programming module, he needs to have SQL, DML and DLL modules already passed. Making such a verification is possible owing to system tables extension with table prefix_promote. Records of this table consisting of user_id, SQL_points, DCL_points, DML_points, DDL_points columns, collect points for the tasks solved correctly. Zero appearing in at least one of the columns in this table or lack of a record for a specified student means that he has not yet realized all the needed tasks and is not prepared for training issues from TSQL module. The situation when a course participant has already acquired essential knowledge and has omitted particular course modules is also accepted. For such students there is a test prepared, consisting of interactively realized operations of data selection and modification, and of creating database objects. In such cases TSQL module form opens with a new button test yourself and deactivated create database (Fig. 15).

Fig. 15 Form displayed for students with no credit

After choosing the first one, next form containing the test is being opened (Fig. 16). The test is divided into groups, in accordance with SQL, DCL, DDL, DML modules, represented by adequate buttons. During the test it is accepted to make one mistake in each of the test tasks. Exceeding this number of mistakes results in being excluded from a particular part of the classes. Performing the previous SQL, DML and DDL tasks can change this situation.

Fig. 16 DCL task complete window

Successfully finished part of the test is signaled by appropriate message and deactivation of a given button (Fig. 17).

Fig. 17 The result of successfully completed DCL test

The code performing these functions is included in view_php file and consists of steps presented below: function SolveDCL(){ var commandTxt = prompt ("task content", ""); if (commandTxt is correct){ //update column DCL_points in prefix_promote table alert ("Very good! You qualify DCL part of test."); document.getElementById('btn2').setAttribute('disabled', }

'disabled');

else alert("Wrong answer! Try again later."); }

When all missing parts are accepted, create database button is activated and student can continue his work by typing his own procedure or by loading it from a file (Fig. 18).

Fig. 18 TSQL window with Load Procedure button

5 Conclusions In the paper the possibility of using e-learning platform as an environment for education of database issues has been analyzed. Among them, basic database objects and users creation, analysis and management of a transaction were considered. For this purpose appropriate modules: DDL, DCL – for the first tasks and DML with ACID for second one, were created. Besides, the database programming has also been discussed. The architecture of all modules is similar but their functionality enforced introducing of specific solutions suitable for tasks that modules should implement. For example DML, DDL and DCL ones include database creation for every user of the platform to ensure independency in his task realization. The ACID module, on the other hand, possesses complex functionality connected with transaction management. Proposed functionalities were verified by the group of 12 students of Computer Science Faculty. During the tests, the correctness and efficiency of queries execution via MODDLE platform were compared with results achieved for the same group of tasks performed on a local and remote database servers. Results obtained in all of the mentioned environments were comparable. Response time was the shortest for local connections. Time delay achieved in case of

both remote connections didn't have any influence on the comfort of work and wasn’t significant. All of the extensions were made using php scripts and were tested in the chosen database servers: MySQL, MS SQL Server and Oracle DBMS. Results of all tests were satisfactory, confirming preliminary assumptions for using e-learning MOODLE platform in the interactive teaching of database issues.

References [Bylina at al. 2008] Bylina B, Walczyński T, Bylina J (2008) The Review of E-learning Operation Basing Upon an Activity of Students and Lecturers, Advanced problems of Internet Technologies, Academy of Business in Dąbrowa Górnicza. [Gumińska and Madejski 2007] Gumińska M, Madejski J (2007) Web based e-learning platform as a source of the personalised teaching materials, Journal of Achievements in Materials and Manufacturing Engineering, Vol. 24, Issue, http://www.journalamme.org/papers_vol24_2/24251.pdf, 2009. [Harezlak and Werner 2010] Harezlak K, Werner A (2010) E-learning Database Course with Usage of Interactive Database Querying, Internet – Technical Development and Applications Series: Advances in Intelligent and Soft Computing , Vol. 64, ISBN: 978-3-642-05018-3. [Garcia-Molina and al. 2003] Garcia-Molina H, Ullman J D, Widom J, (2003) Database System Implementation, WNT, Warszawa, Poland (in Polish). [Welling and Thomson 2005] Welling L, Thomson L. (2005) PHP and MySQL Web Development (3rd Edition), Helion, Poland (in Polish). [Swan 2009] Swan B. (2009) Acquiring access to SQL Server databases using PHP, http://www.microsoft.com/poland/technet/bazawiedzy/centrumrozwiazan/cr360_01.mspx (in Polish).

Suggest Documents