Morfik Database Guide - Introduction to Morfik Database Programming

From Morfikwiki.com

Jump to: navigation, search

The AppsBuilder offers native, built-in, support for database programming. Actually, Morfik AppsBuilder was conceived, right from the start to work with a database and to create applications which are database driven. This guide will provide a quick view to all aspects of database programming with Morfik AppsBuilder, from creating tables to accessing external, third-party, databases.

The creation of the web interface for presenting database information will also be extensively covered since this is tightly coupled to database access in the Morfik workspace and Framework.

The information in the topics that compose the Database Guide is focused on Morfik Web Application projects, as these have a server-side component to them, enabling the usage of real databases. Only a subset of this information applies to Morfik Browser Application projects, which use XML Data Sources.


Contents


[edit] Database Theory

This guide presumes that you are at least familiar with the general concepts of relational databases such as tables, indices and queries. Detail will be provided on how to create and use these constructs in the Morfik workspace and in Morfik applications, but not to the concepts behind them since it would be beyond the scope of this text.

Concepts with which the reader should be familiar include tables and data types, indices, primary and foreign keys, relationships and constraints. A basic knowledge of SQL will make some of the text easier to understand but may not be a requirement since this guide does go over the major SQL constructs which are normally used from within a Morifk XApp (Morfik built, web based application).

Note
Almost all SQL commands in this guide, except when otherwise specified, are written in Firebird’s specific SQL dialect. Exceptions might exist when covering work with external databases and will be clearly indicated.

[edit] The Built-in Database

Morfik has a built-in database management system which is used in all new AppsBuilder Web projects. This makes it very easy to start new projects from scratch in Morfik, since there is no need to request database access from a DBA or any such formalities. Of course, you still have to go through the appropriate steps in order to deploy a production application, but there is no delay in getting started.

The built-in database is a full featured relational database server called Firebird. Morfik makes use of many advanced features of Firebird transparently allowing the developer to benefit from them without having to learn how to use them directly. This allows developers to quickly go from being a novice to creating sophisticated data driven applications.

Every AppsBuilder Web Project has an associated database, as part of the project’s structure. When you go to the tables view of the AppsBuilder Designer tab, you can create new tables in this, default database. Morfik AppsBuilder Workspace allows the developer to created tables without having to resort to an external tool.

For those who are familiar with the Firebird database server and its usage, Appendix A provides additional details on how certain things are implemented by Morfik at the database level.

[edit] Database Driven Applications/Sites

Morfik WebOS AppsBuilder was designed, from the ground up, for the creation of database driven applications and websites. Since data access is not an addition, but an integral part of the design of the product, the very manner in which you design an application or site is heavily influenced by what data is going to be shown. It is possible to create totally dynamic applications, where all content comes directly from database tables and no static content is used. Again, due to how AppsBuilder and the Morfik Framework are built this is, actually, the preferred way of creating applications/sites.

It is quite simple, with Morfik, to create sophisticated data-driven applications. This makes Morfik the tool of choice for any kind of web-base applications which need to dynamically alter its layout, and content.

[edit] Visual Development

The vast majority of work that goes into a Morfik XApp is in the form of visual design and configuration. This holds true for the database access parts as well. Of course, there will be times when a developer will need or want to write some database access code, for a specific purpose. Most of the work, however, can be done through the visual designers and wizards.

Morfik AppsBuilder includes visual designers for Tables, Queries and Relationships as well as Wizards for creating these objects and the visual interface elements which will be associated with them.

[edit] Stored Queries

The Morfik Workspace allows the developer to visually create and edit SQL queries. Once the queries are created they can be used to link interface elements to actual data in the database without the developer having to insert SQL command strings in the applications interface code. In this respect, Morfik treats the stored queries in just the same way it does tables.

Actually, due to its tight coupling to the database Morfik uses database content to help you create the application/site’s interface with a lot less coding than any other web development tool.

In Figure 1 you can see the visual query builder in Morfik AppsBuilder Workspace showing the view where tables, fields and criteria are selected.

Figure 1 – Morfik AppsBuilder Visual Query Builder

[edit] Content Management

In the world of the Web, and especially what has come to be considered Web 2.0, content is king. One of the main factors in considering a company and/or website as being Web 2.0, is that it derives, in some way, content from its own users, thus creating value from their interaction with their users. In this world, managing the content of a site is its very reason to exist, so special systems have been created to help individuals and companies get of the ground quickly. These Systems are generically called Content Management Systems (CMS).

In the first part of this guide we will look at how an application which is totally dynamic can be created in as simple a manner as possible. We will create a basic content management systems (CMS) as way to show how to tap into the power available within Morfik AppsBuilder and Morfik Framework for creating database driven applications. We will add extra functionality to this application as it suites our need to cover other aspects of database access which will yield a richer application in the end.

[edit] Multi-Database Projects

Apart from the ability to import data from other databases Morfik AppsBuilder allows you to create projects that access multiple databases. These can be separate databases in the same database management system (DBMS) or from entirely different DBMSs. This can useful in many different ways such as creating a web site that publishes data from a pre-existing corporate database or for distributing load amongst different servers in high concurrency, high volume online systems.

All access to databases other than Firebird is done through industry standard ODBC drivers.

[edit] Mixing Databases

Though Morfik AppsBuilder does not enable you to run heterogeneous queries against multiple distinct databases, it does allow you to very easily retrieve related information in diverse databases and present it to the end user through a web interface.

There is no limitation in the number and type of databases you can combine in a Morfik project, as long as the respective DBMS has an ODBC driver.

This topic is covered extensively in chapter 4 of this guide.

[edit] Basic Common View and Concepts

Independent of which language database you have chosen for your usage, as I mentioned, you will work with the same concepts. Morfik AppsBuilder presents all tables used in an application in its Table View. The only notable difference will be that the external (non-native) tables will have a small arrow painted over their icons. Conceptually, to the Workspace they are exactly the same. Since the stored query is a Morfik specific concept all queries will show in the same manner in its Query View. When working with code there will be some differences between using a Firebird database (be it the default or an external one) and all other databases.

Figure 2 – Morfik AppsBuilder Table View showing a project
with two external tables.

In Figure 2 you can see a list of tables in Table View which include two external tables. The external tables show with a different icon in the Table View.

[edit] Wrapping it up

Morfik AppsBuilder offers support for creating sophisticated applications using its built-in support for Firebird. Creating applications with the default database does not depend on any application outside Morfik AppsBuilder. Support for other DBMSs, from all vendors is accomplished through the industry standard ODBC interface.

Developers can easily create applications/sites that access multiple databases, including databases from different vendors, and present the information in a clear and simple manner through a Web interface.

[edit] See Also

Personal tools