Thursday, July 26, 2007

PostgreSQL: The world's most advanced open source database

Download Postgre Sql PgAdmin : Download Now Version 4.1.3

PostgreSQL is a powerful, open source relational database system. It has
more than 15 years of active development and a proven architecture that has
earned it a strong reputation for reliability, data integrity, and
correctness. It runs on all major operating systems, including Linux, UNIX (AIX,
BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It is
fully ACID compliant, has full support for foreign keys, joins, views, triggers,
and stored procedures (in multiple languages). It includes most SQL92 and SQL99
data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL,
and TIMESTAMP. It also supports storage of binary large objects, including pictures,
sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl,
Python, Ruby, Tcl, ODBC, among others.

An enterprise class database, PostgreSQL boasts sophisticated features
such as Multi-Version Concurrency Control (MVCC), point in time recovery,
tablespaces, asynchronous replication, nested transactions (savepoints),
online/hot backups, a sophisticated query planner/optimizer, and write ahead logging
for fault tolerance. It supports international character sets, multibyte
character encodings, Unicode, and it is locale-aware for sorting,
case-sensitivity, and formatting. It is highly scalable both in the sheer quantity
of data it can manage and in the number of concurrent users it can
accommodate. There are active PostgreSQL systems in production environments that
manage in excess of 4 terabytes of data. Some general PostgreSQL limits are
included in the table below.

LimitValue
Maximum Database SizeUnlimited
Maximum Table Size32 TB
Maximum Row Size1.6 TB
Maximum Field Size1 GB
Maximum Rows per TableUnlimited
Maximum Columns per Table250 - 1600 depending on column types
Maximum Indexes per TableUnlimited


PostgreSQL has won praise from its users and industry recognition, including the Linux New Media Award for Best Database System and three time winner of the The Linux Journal Editors' Choice Award for best DBMS.


Featureful and Standards Compliant

PostgreSQL prides itself in standards compliance. Its SQL implementation
strongly conforms to the ANSI-SQL 92/99 standards. It has full support for
subqueries (including subselects in the FROM clause), read-committed and
serializable transaction isolation levels. And while PostgreSQL has a fully
relational system catalog which itself supports multiple schemas per database,
its catalog is also accessible through the Information Schema as defined in the
SQL standard.

Data integrity features include (compound) primary keys, foreign keys with
restricting and cascading updates/deletes, check constraints, unique
constraints, and not null constraints.


It also has a host of extensions and advanced features. Among the
conveniences are auto-increment columns through sequences, and
LIMIT/OFFSET allowing the return of partial result
sets. PostgreSQL supports compound, unique, partial, and functional indexes
which can use any of its B-tree, R-tree, hash, or GiST storage methods.

GiST

(Generalized Search Tree) indexing is an advanced system
which brings together a wide array of different sorting and searching algorithms
including B-tree, B+-tree, R-tree, partial sum trees, ranked B+-trees and many
others. It also provides an interface which allows both the creation of custom
data types as well as extensible query methods with which to search them. Thus,
GiST offers the flexibility to specify what you store,
how you store it, and the ability to define new
ways
to search through it --- ways that far exceed those offered by
standard B-tree, R-tree and other generalized search algorithms.

GiST serves as a foundation for many public projects that use PostgreSQL
such as OpenFTS and PostGIS. OpenFTS (Open Source Full
Text Search engine) provides online indexing of data and relevance ranking for
database searching. PostGIS is a project which adds support for geographic
objects in PostgreSQL, allowing it to be used as a spatial database for
geographic information systems (GIS), much like ESRI's SDE or Oracle's Spatial
extension.


Other advanced features include table inheritance, a rules systems, and
database events. Table inheritance puts an object oriented slant on table
creation, allowing database designers to derive new tables
from other tables, treating them as base classes. Even better, PostgreSQL
supports both single and multiple inheritance in this manner.

The rules system, also called the query rewrite
system
, allows the database designer to create rules which identify
specific operations for a given table or view, and dynamically transform them
into alternate operations when they are processed.

The events system is an interprocess communication system in which
messages and events can be transmitted between clients using the
LISTEN and NOTIFY commands, allowing both
simple peer to peer communication and advanced coordination on database
events. Since notifications can be issued from triggers and stored procedures,
PostgreSQL clients can monitor database events such as table updates, inserts,
or deletes as they happen.


Highly Customizable



PostgreSQL runs stored procedures in more than a dozen programming languages, including Java, Perl, Python, Ruby, Tcl, C/C++,
and its own PL/pgSQL, which is similar to Oracle's PL/SQL. Included with its
standard function library are hundreds of built-in functions that range from
basic math and string operations to cryptography and Oracle
compatibility. Triggers and stored procedures can be written in C and loaded
into the database as a library, allowing great flexibility in extending its
capabilities. Similarly, PostgreSQL includes a framework that allows developers
to define and create their own custom data types along with supporting functions
and operators that define their behavior. As a result, a host of advanced data
types have been created that range from geometric and spatial primitives to
network addresses to even ISBN/ISSN (International Standard Book
Number/International Standard Serial Number) data types, all of which can be
optionally added to the system.

Just as there are many procedure languages supported by PostgreSQL, there
are also many library interfaces as well, allowing various languages both
compiled and interpreted to interface with PostgreSQL. There are interfaces for
Java (JDBC), ODBC, Perl, Python, Ruby, C, C++, PHP, Lisp, Scheme, and Qt just to
name a few.

Best of all, PostgreSQL's source code is available under the most liberal
open source license: the BSD license. This license gives you the freedom to use,
modify and distribute PostgreSQL in any form you like, open or closed
source. Any modifications, enhancements, or changes you make are yours to do
with as you please. As such, PostgreSQL is not only a powerful database system
capable of running the enterprise, it is a development platform upon which to
develop in-house, web, or commercial software products that require a capable
RDBMS.

Sunday, July 22, 2007

Yahoo! User Interface Library

The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. The YUI Library also includes several core CSS resources. All components in the YUI Library have been released as open source under a BSD license and are free for all uses.


Download the entire library, API documentation, and functional examples from Sourceforge.


Using YUI:


Searchable API Documentation

API docs are availabe for every YUI component. You can search the API documentation with instant filtering on the main API page.

Tuesday, July 17, 2007

Ultimate Web 2.0 Layer Styles

Web 2.0 Layer Layout Badges Gradients by Photoshop

Create your Web look great in Web 2.0 Styles with Photoshop (.PSD, .ASL, .PNG, .grd)


1. Ultimate Web 2.0 Layer Styles

131 Photoshop Layer Styles created in .ASL ( Photoshop Layer Style ) format.


2. 10 Web Layout Design Elements


3. Web 2.0 Badges

Badges are a key requirement for any basic website too. Here is a set of very cool Web 2.0 Badges for you in .PSD and .PNG formats.


4. Ultimate Web 2.0 Gradients

Gradients are one of the most important aspects to be considered while designing a Web 2.0 Site.

Monday, July 16, 2007

21 Things You Must Know About CakePHP

Easily creating static pages

I needed to create several pages that didn't use any models and contained static data inside the default layout. My first thought was to create a controller for these pages and define an action for each static page I needed. However, this solution seemed tedious and would make it difficult to quickly add new pages. Enter the pages controller - simply create a view inside the views/pages/ folder and it'll automatically be rendered in /pages. For example, if I created /views/pages/matt.thtml it would be accessible via http://www.example.com/pages/matt

Static pages - Adjusting the page title

If you're using the pages controller and you need to change the page title, add the following to your view:
<? $this->pageTitle = 'Title of your page.'; ?>

Static pages - Adjusting other data sent to the layout

If you need to send data to the layout (such as a variable indicating what section to highlight on the nav bar), add this to your view:

<? $this->_viewVars['somedata'] = array('some','data'); ?>

That array should then be accessible as $somedata inside your layout.

Creating a simple admin center

If you need to create an administrative back-end for your CakePHP site and would like all the actions with administrative capabilities to exist under a specific folder, open up config/core.php and uncomment:
define('CAKE_ADMIN', 'admin');
This will then make all actions that are prefixed with "admin_" to be accessible via:
/admin/yourcontroller/youraction. For instance, if I created an action in my posts controller called "admin_add," I would access this via: www.example.com/admin/posts/add
From there I could simply password the admin folder to prohibit unwanted users from adding posts.

Viewing the SQL queries that are running behind the scenes

You can easily see the SQL queries that CakePHP is running by adjusting the DEBUG constant in config/core.php. 0 is production, 1 is development, 2 is full debug with SQL, and 3 is full debug with SQL and dump of the current object. I typically have debug set at 2, which renders a table at the bottom of the page that contains SQL debug information.
If rendering a table at the bottom of your site is constantly breaking your layout during development (especially if you're making AJAX calls and you're getting SQL inside your pages, not just the bottom), you can easily style this table to be hidden by adding this to your CSS:
.cakeSqlLog { display: none; }
This will allow you to view debug information in the HTML source code without your layout getting mangled, just don't forget to set debug back to 0 when your site goes live.

Multiple sources of documentation

Don't just rely on the manual. The wiki and the API are invaluable sources of information. The tutorials in the wiki are especially useful, and the API may be daunting at first, but you'll quickly find the information in there is crucial to building a site with CakePHP.

Using bake.php

Bake is a command line PHP script that will automagically generate a model, controller, and views based on the design of your database. I highly recommend using scaffolding to get a prototype going of a table that may change a lot in the beginning. If you're fairly certain the data is not subject to any drastic change, I recommend using bake instead. With bake all the files are generated and written to disk and you can make modifications from there. It saves a lot of time doing the repetitive tasks such as creating associations, views, and the basic CRUD controller operations.
Using bake is really easy. Once you have a table(s) in your database created, change directories to the /cake/scripts/ folder and run:
php bake.php
If you choose to bake interactively it'll walk you through the steps required to create your model, controller, and views. Once everything has been baked I usually go through all the generated code and make custom modifications as needed.

Mind permissions when moving cake around

When I changed from the development server to the live server I tarred up my entire cake directory and scp'd it to the new server. Immediately I started having an issue where any time the debug level was set to 0 (production mode), data would not be returned for certain database calls. This was a bit of a catch 22 since I needed to view debug information to troubleshoot the problem.
Someone in #cakephp kindly pointed out that permissions on the /app/tmp folder need to be writeable by apache. I changed the permissions to 777 and the issue went away.

Complex model validation

I needed to validate beyond just checking to make sure a field wasn't empty or it matched a regular expression. In particular, I needed a way to verify that the email address users registered with was unique. In the wiki I found this gem: this advanced validation tutorial, which covers some advanced methods of validation that were very useful.

Logging errors

$this->log('Something broke');
This will log your error to /tmp/logs/ (I initially made the mistake of thinking it would log it to the apache error log)

Creating a controller that uses other models

Suppose you have a controller that needs data from a bunch of different models, simply add this to the top of your controller:
class yourController extends AppController
{
var $uses = array('Post','User');
}

This controller would then have access to both the Post and the User model.

Creating a model for a table that doesn't actually exist in the database

I needed a way to create a model and controller without actually having an associated table in the database. I particularly wanted to make use of the $validate array so I could easily validate my fields and keep the validation logic in the model. CakePHP will throw an error if you create a model for a table that doesn't exist. Adding this to the model fixed the problem:
var $useTable = false;
You can use this to change tables names as well.
var $useTable = 'some_table';

Call exit() after redirecting

This should be no surprise to anyone who has done any serious web development in the past, but make sure you call exit() after running $this->redirect() if there's code afterward that you don't want to run. I've always done this in the past, but I made the assumption that $this->redirect() would make an exit call for me (which it didn't).

Advanced model functions

Unless you delve in to the API, there are some very useful model functions at your disposal you might not know exist. I highly recommend reading over the Model Class Reference at least once. Here's a few key functions I wasn't aware of that I found to be very useful:

  • generateList() - I use this function primarily to populate select boxes with data from associated tables
  • findBySql() - Sometimes you just need to write your own SQL
  • findCount() - Returns number of rows matching given SQL condition
  • hasAny() - Returns true if a record that meets the given conditions exists.

Again, I highly recommend reading over the entire model class reference, you'll be surprised at what you learn.

Inserting multiple rows in succession

I had a situation where I needed to iterate through a list of items and insert new rows for each. I quickly discovered that if you insert an item and then immediately insert another, the item that is inserted next doesn't insert at all. Instead the previously inserted row was being updated. For example:
$items = array('Item 1','Item 2','Item 3');
foreach ($items as $item) {
  $this->Post->save(array('Post' => array('title' => $item)));
}

This code will result in a single entry in the posts table: "item 3." CakePHP inserted "item 1", but then updates it to become "item 2," then "item 3" because $this->Post->id gets the value of the last inserted ID. Normally this functionality is very useful, but in this particular instance it was not. I found was to setting $this->Post->id = false after each insert solved the problem.

Inserting logic before or after controller functions

Suppose you needed an array of colors to be available to every view rendered by your controller but you don't want to have to define this data in every action. Using the beforeRender() callback will allow you to do this:
function beforeRender() {
  $this->set('colors',array('red','blue','green');
}

This would make $colors accessible in every view rendered by that controller. beforeRender() is called after the controller logic and just before a view is rendered.
There's also beforeFilter() and afterFilter(), which are called before and after every controller action. For more information, read up on callbacks in the models section of the manual.

Adding a WYSIWYG editor to CakePHP

I found this great tutorial on getting TinyMCE set up with CakePHP. Basically you just link the tiny_mce .js file to your page and then add a small bit of init code to every page that you want textareas to be converted into TinyMCE editors.

Writing your own SQL for HABTM relationships

I had an issue with trying to create a HABTM (has-and-belongs-to-many) relationship where I needed to specify my own SQL statement. According to the docs (at the time of this writing) you should set finderSql in your model, but according to the cakePHP source you should set finderQuery instead. It's just a foul-up in the docs, but I figured it'd be worth noting to save others from having to figure it out for themselves. Trac ticket here: https://trac.cakephp.org/ticket/1217

Sending email

I found two tutorials in the wiki: Sending email and Sending email with PHPMailer
I highly recommend the latter of the two, sending emails with PHPMailer is more secure and there's less of a headache because you don't have to deal with constructing the mail headers yourself.

Customizing HTML generated by the Helper

I needed to change the default <option> generated when I called $html->selectTag() to say something like "Please Select" rather than an empty space (default). I also wanted radio buttons to have labels so the user doesn't have to click exactly on the radio button itself but can instead click anywhere on the text associated with it.
Create the file /app/config/tags.ini.php and add the following:
; Tag template for a input type='radio' tag.
radio = "<input type="radio" name="data[%s][%s]" id="%s" %s /><label for="%3$s">%s</label>"
; Tag template for an empty select option tag.
selectempty = "<option value="" %s>-- Please Select --</option>"

You can get a full list of available tags in /cake/config/tags.ini.php. I wouldn't recommend modifying that file, however, because you could lose your changes when you upgrade CakePHP.

Creating a custom 404 error page

If you need to change the page that users see when a document is not found, create:
/app/views/errors/error404.thtml

Sunday, July 8, 2007

Sending XML files to a Webservice (Using cURL)

Calling Web Services. Great fun!! … when it works. One of the biggest challenges is to send the XML document and get the response back, an XML document in particular. I have come up with a PHP function that hides all the necessary logic from theuser and handles the posting of the XML document and returns whatever the server responds. It relies on PHP’s cURL library (so you need it properly configured on your server in order to work). All you need to do is create the XML document, choose the URL (and port) to which you want to post the XML document and the function takes care of the rest. Below is the function code. As you can see, the function can handle SSL-enabled servers, something that provides a great advantage, since many Web services run on HTTPS.

// open a http channel, transmit data and return received buffer
function xml_post($post_xml, $url, $port)
{
$user_agent = $_SERVER[’HTTP_USER_AGENT’];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
if($port==443)
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

The example below shows how the function works, by posting a XML document of the form
<?xml version=”1.0″ encoding=”iso-8859-1″?>

<Document> 

  <Message> 

     Your Name  

  </Message>

</Document>
to a “listener” script, which takes the XML document and returns a reply (another XML document). In this case, the listener is very simple. All it does is replace the “Message” tag with “Reply” and print the resulting XML. Of course, the listener can do all sorts of things in response to the POST.

<?php 

   if ( !isset( $HTTP_RAW_POST_DATA ) )

   {

      $HTTP_RAW_POST_DATA = file_get_contents( ‘php://input’ ); 

   } 

   $xml = str_replace(”Message”,”Reply” , $HTTP_RAW_POST_DATA);  


   print((trim($xml)));

?>



You can download the function code, as well as a working example here. Let me know what you think.

Saturday, July 7, 2007

Prototype Javascript Framework





Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.

Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere.


Welcome to the API documentation for Prototype. The left column contains the main sections. When you activate a section, its detailed contents then appears at the top of the column.

We are doing our best to provide you with current, clear, example-rich documentation. The goal here is that you should, when reading it, get the same warm, fuzzy feeling as we do when using Prototype :-)

The API documentation is a reference documentation. If you need to learn how to use Prototype, or to acquire skills in a particular feature area, have a look at the Learn section, which is accessible from the top of all pages (the “Tips and Tutorials” link), and is also linked from the orange bar in all reference pages. Documentation in the Learn section is more narrative and tutorial-style.

Enjoy the docs!
Documentation tools and bundles

* downloadable PDF version by Josh Clark
* downloadable CHM version by Kjell Bublitz
* API Search Bookmarklet: Drag this bookmark to your browser’s toolbar. Type in a method to view its documentation. For example, Event.observe. Search Prototype API
* Dashboard widget
* Firefox sidebar

Archives

For those of you using older versions of Prototype, you can download corresponding PDF versions of the docs below, courtesy of Josh Clark.

* Version 1.5.1
* Version 1.5.0

Source