<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vladimir Cvetic &#187; Database</title>
	<atom:link href="http://www.hazaah.com/cat/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hazaah.com</link>
	<description>buffle the world</description>
	<lastBuildDate>Thu, 12 Nov 2009 14:30:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ferdinand.Slider &#8211; Javascript news slider</title>
		<link>http://www.hazaah.com/programming/ferdinand-slider/</link>
		<comments>http://www.hazaah.com/programming/ferdinand-slider/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 14:59:37 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.hazaah.com/?p=121</guid>
		<description><![CDATA[Moved
Go to new addres >>

location.href="http://ferdinand.rs/javascript/ferdinandslider";

]]></description>
			<content:encoded><![CDATA[<h1>Moved</h1>
<p><a href="http://ferdinand.rs/javascript/ferdinandslider">Go to new addres >></a><br />
<script>
location.href="http://ferdinand.rs/javascript/ferdinandslider";
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/programming/ferdinand-slider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Always fresh: Sql list of countires</title>
		<link>http://www.hazaah.com/programming/always-fresh-sql-list-of-countires/</link>
		<comments>http://www.hazaah.com/programming/always-fresh-sql-list-of-countires/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 11:01:49 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Something Else]]></category>
		<category><![CDATA[countries list]]></category>
		<category><![CDATA[fresh countries list]]></category>
		<category><![CDATA[iso countries]]></category>
		<category><![CDATA[mysql countires list]]></category>
		<category><![CDATA[sql countires list]]></category>
		<category><![CDATA[up to date countries list]]></category>

		<guid isPermaLink="false">http://www.hazaah.com/?p=70</guid>
		<description><![CDATA[Since my last post with updated list of countries in MySQL format was so well received I decided to go even further and write a parser script so you can always get fresh countries list.
Every time you download sql countries list it will be up to date for that very minute. This is because it [...]]]></description>
			<content:encoded><![CDATA[<p>Since my last post with updated list of countries in MySQL format was so well received I decided to go even further and write a parser script so you can always get fresh countries list.</p>
<p>Every time you <a href="/download/countries.sql.php">download</a> sql countries list it will be up to date for that very minute. This is because it is fetched and parsed from ISO.org just for your pleasure, every time you download (well if you don&#8217;t mind a bit of caching :P)</p>
<div style="border:1px solid #ccc;padding:6px;">
Enough talk&#8230; <a href="/download/countries.sql.php"><strong>Download</strong></a> MySQL countries list.
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/programming/always-fresh-sql-list-of-countires/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unrar recursively multiple archives (linux and mac)</title>
		<link>http://www.hazaah.com/programming/unrar-recursevly-linux-mac/</link>
		<comments>http://www.hazaah.com/programming/unrar-recursevly-linux-mac/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 07:11:02 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.hazaah.com/?p=69</guid>
		<description><![CDATA[It really is a drag when you download full season of your favorite show and see 20+ episodes in separate folders, every episode rared. It takes a bit of time to unpack one by one.
Here&#8217;s a little script that should help you with that (and with similar tasks). Download.
Install:

gunzip unrarr.gz
sudo cp unrarr /usr/bin/
sudo chmod +x [...]]]></description>
			<content:encoded><![CDATA[<p>It really is a drag when you download full season of your favorite show and see 20+ episodes in separate folders, every episode rared. It takes a bit of time to unpack one by one.</p>
<p>Here&#8217;s a little script that should help you with that (and with similar tasks). <strong><a href="http://hazaah.com/download/unrarr.gz">Download</a></strong>.<br />
Install:</p>
<pre>
gunzip unrarr.gz
sudo cp unrarr /usr/bin/
sudo chmod +x /usr/bin/unrarr
</pre>
<p>Usage:</p>
<pre>
unrarr /path/to/folder
</pre>
<p>Edit:<br />
To check rar files (through svf files) for consistency CVF package must be installed (<a href="http://cfv.sourceforge.net" target="_blank">cfv.sourceforge.net</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/programming/unrar-recursevly-linux-mac/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Up to date sql list of countries &#8211; 31-07-2008</title>
		<link>http://www.hazaah.com/programming/up-to-date-sql-list-of-countries-31-07-2008/</link>
		<comments>http://www.hazaah.com/programming/up-to-date-sql-list-of-countries-31-07-2008/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 08:52:58 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[countries list]]></category>
		<category><![CDATA[mysql countries list]]></category>
		<category><![CDATA[sql countries]]></category>
		<category><![CDATA[up to date countries list]]></category>

		<guid isPermaLink="false">http://www.hazaah.com/?p=68</guid>
		<description><![CDATA[Just collected list of countries and formatted it into MySQL form&#8230; well nothing much but I bet it will be useful to someone out there. Well enjoy: Countries List SQL download

Even fresher SQL Countries list&#8230; here.

]]></description>
			<content:encoded><![CDATA[<p>Just collected list of countries and formatted it into MySQL form&#8230; well nothing much but I bet it will be useful to someone out there. Well enjoy: <a href="http://hazaah.com/download/countries.sql.gz">Countries List SQL download</a></p>
<div style="border:1px solid #ccc;padding:6px;">
<a href="http://www.hazaah.com/programming/always-fresh-sql-list-of-countires/">Even fresher SQL Countries list&#8230; here.</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/programming/up-to-date-sql-list-of-countries-31-07-2008/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Guide to simple Database Abstraction</title>
		<link>http://www.hazaah.com/programming/guide-to-simple-database-abstraction/</link>
		<comments>http://www.hazaah.com/programming/guide-to-simple-database-abstraction/#comments</comments>
		<pubDate>Mon, 27 Aug 2007 09:31:32 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/programming/guide-to-simple-database-abstraction/</guid>
		<description><![CDATA[A database abstraction layer is an application programming interface which unifies the communication between a computer application and databases such as MySQL, Oracle or SQLite. Traditionally, all database vendors provide their own interface tailored to their products which leaves it to the application programmer to implement code for all database interfaces he would like to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>A database abstraction layer is an application programming interface which unifies the communication between a computer application and databases such as MySQL, Oracle or SQLite. Traditionally, all database vendors provide their own interface tailored to their products which leaves it to the application programmer to implement code for all database interfaces he would like to support. Database abstraction layers reduce the amount of work by providing a consistent API to the developer and hide the database specifics behind this interface as much as possible.</p></blockquote>
<p>
I will try to guide you through creating your own database abstraction php class.
</p>
<h3>1. Creating database object</h3>
<p>Define abstraction class.</p>
<pre class="php" name="code">
class Dapc {
}
</pre>
<p>Next thing we will do is create class method which will allow you to load specific data into php object. This method we will name init(). This method will need primary key, table name and array with table fields. We will define them later, don&#8217;t worry about that.</p>
<pre class="php" name="code">
class Dapc {

  function init() {
    global $mysqli; // db connection holder... object.
    $mysqli->stmt_init();
    $key = $this->primary_key; // primary key
    $sql = "SELECT * FROM ".$this->table_name." where ".$this->primary_key." = ".$this->$key;
    $stmt = $mysqli->query($sql) or trigger_error('SQL QUERY ERROR: '.$sql);
    $obj = $stmt->fetch_array();
    foreach($this->fields as $k=>$v) {
      $this->$k = $obj[$k];
    }
    $this->object_loaded = 'Y';
    return true;
  }
}
</pre>
<p>Now what we have done here? We created sql query which will select all fields from given table ($this->table_name) which primary key ($this->primary_key) has value $this->$key and then loaded all those fields in single object.</p>
<h3>Abstraction Interface</h3>
<p>Above we have created bottom layer of our db abstraction. To use this we will need another layer which I call &#8220;interface&#8221;. This layer will keep you away from database. Lets create it.</p>
<p>First say we have example mysql table looking like this:</p>
<pre class="sql" name="code">
CREATE TABLE email
(
   ID INT NOT NULL AUTO_INCREMENT,
   name VARCHAR(35) NOT NULL,
   email VARCHAR(35) NOT NULL,
   PRIMARY KEY (ID)
);
</pre>
<p>Now that we have mysql table we can create little interface class. This class will extend our Dapc class. We will name this class something like {table_name}DAPC and define some variables. First primary key of our table (email) which is ID, next table name and finally table fields array. Table fields should be exactly like our fields in DB table. Form is &#8216;field_name&#8217;=>&#8217;field_type&#8217; finally we will define simple flag which will tell us if object is loaded or not.</p>
<pre class="php" name="code">
class emailDAPC extends Dapc {
  var $primary_key = 'id';
  var $table_name = 'email';

  protected $fields = array(
   'id'=>'int',
   'name'=>'string',
   'email'=>'string'
  );
  var $object_loaded = 'N';
}
</pre>
<p>Next we will create method for emailDAPC class called initData(). It is very simple and will only call init method from our DAPC class.</p>
<pre class="php" name="code">
function initData() {
    $this->init();
 }
</pre>
<p>And constructor&#8230;</p>
<pre class="php" name="code">
 function emailDAPC($id=-1) {
    if ($id!=-1) {
      $key = $this->primary_key;
      $this->$key = $id;
      $this->initData($id);
    }
    return true;
  }
</pre>
<p>Lets see what have we done so far&#8230; If we load class with value 12, email object will load fields and values from table email.</p>
<pre class="php" name="code">
$email = new emailDAPC(12);
print_r($email);
/*Output
email Object
(
    ...
    [object_loaded] => 'Y'
    [id] => 12
    [email] => 'person@example.com'
    [name] => 'Some Person'
    ...
)
*/
</pre>
<h3>Inserting/Updating DB data</h3>
<p>To insert data in table we will need to create another method in bottom layer. This method will be called insert(). We will do similar thing as with init() :</p>
<pre class="php" name="code">
  function insert() {
    global $mysqli;
    unset($stmt);
    $i = 0;
    foreach($this->fields as $k=>$v) {
      if ($obj->$k != $this->$k) {
        if ($i==0) $a = '';
        else $a = ' , ';
        if ($v=='int') $this->sql_prep .= $a.$k.'='.$this->$k;
        else $this->sql_prep .= $a.$k.'="'.$this->$k.'"';
        $i++;
      }
    }
    $sql = "INSERT INTO ".$this->table_name." SET ".$this->sql_prep;

    trigger_error('--> INSERT');
    trigger_error('Executing SQL: '.$sql);
    $mysqli->stmt_init();

    $stmt = $mysqli->prepare($sql) or trigger_error('SQL QUERY ERROR: '.$sql);
    $stmt->execute();
  }
</pre>
<p>We looped fields array (remember that we defined it in interface class) and create query. Very simple.</p>
<p>To be able to update rows we will create update method:</p>
<pre lang="php" name="code">
  function update() {
    global $mysqli;
    $mysqli->stmt_init();
    $key = $this->primary_key;
    $sql = "SELECT * FROM ".$this->table_name." where ".$this->primary_key." = ".$this->$key;
    $stmt = $mysqli->query($sql) or trigger_error('SQL QUERY ERROR: '.$sql);;
    $obj = $stmt->fetch_array();
    $i = 0;
    foreach($this->fields as $k=>$v) {
      if ($obj->$k != $this->$k) {
        if ($i==0) $a = '';
        else $a = ' , ';
        if ($v=='int') $this->sql_prep .= $a.$k.'='.$this->$k;
        else $this->sql_prep .= $a.$k.'="'.$this->$k.'"';
        $i++;
        trigger_error('<b>PREPARE:</b> <font color="red">'.$obj->$k.'!='.$this->$k.'</font> ('.$key.'='.$this->$key.')');
      }
    }
    unset($stmt);
    $mysqli->stmt_init();
    $sql = 'UPDATE '.$this->table_name.' SET '.$this->sql_prep.' WHERE '.$this->primary_key.'='.$this->$key;
    trigger_error('--> UPDATE');
    trigger_error('Executing SQL: '.$sql);
    $stmt = $mysqli->prepare($sql) or trigger_error('SQL QUERY ERROR: '.$sql);
    $stmt->execute();
  }
</pre>
<p>Again same thing, build query from fields array and exec.</p>
<p>Now to simplify&#8230; we will create another method called saveDapc() If you remember we defined that flag $this->object_loaded we will use this flag so we can know what action is needed (insert or update). If object is loaded and saveDapc() method is called we will assume that update is needed and thus call update method and vice versa.</p>
<pre name="code" class="php">
  function saveDapc() {
    if ($this->object_loaded=='Y') {
      $this->update();
    } else {
      $this->insert();
    }
  }
</pre>
<h3>Saving from interface</h3>
<p>With all this now it is very easy to insert/update database from interface. All we need to do is make another method called save() in our email table interface.</p>
<pre name="code" class="php">
  function save() {
    if (!$this->validate()) {
      return false;
    }
    $this->saveDapc();
  }
 function validate() {
  return true;
 }
</pre>
<p>Here is how you will save data:</p>
<p><b>Insert</b></p>
<pre name="code" class="php">
$email = new emailDAPC();
$email->name='Some person';
$email->email='name@example.com';
$email->save();
// That's all! Data inserted in DB
</pre>
<p>Now say we want to change email for some record. We will simply load it with it&#8217;s id:</p>
<pre name="code" class="php">
$email = new emailDAPC(12);
$email->email='newmail@example.com';
$email->save();
// That's all! Email is changed!
</pre>
<p>Data delete can be done the same way as, say&#8230; update. Simply load object and call method delete().</p>
<p>
As you see with db abstraction it is much easier/faster to work. Beside speed this will also allow to migrate to another sql server with only changing bottom level class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/programming/guide-to-simple-database-abstraction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fulltext boolean search on InnoDB</title>
		<link>http://www.hazaah.com/databases/fulltext-boolean-search-on-innodb/</link>
		<comments>http://www.hazaah.com/databases/fulltext-boolean-search-on-innodb/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 14:41:39 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/vladimir-cvetic/something-else/fulltext-boolean-search-on-innodb/</guid>
		<description><![CDATA[On different MySQL table engines different rules apply. For example on MyIsam you can have Full Text indexes (thus enabling full text search) but you are giving up foreign keys.
I searched the way to get both on out-of-the-box mysql but failed (this can be enabled with use of sphinx mysql plugin). The best thing I [...]]]></description>
			<content:encoded><![CDATA[<p>On different MySQL table engines different rules apply. For example on MyIsam you can have Full Text indexes (thus enabling <a href="http://www.knowbies.com/vladimir-cvetic/databases/mysql/fulltext-search-mysql/">full text search</a>) but you are giving up <a href="http://www.knowbies.com/vladimir-cvetic/databases/2-deo-referencijalni-interitet-u-mysql-bazama-podataka/">foreign keys</a>.</p>
<p>I searched the way to get both on out-of-the-box mysql but failed (this can be enabled with use of <a href="http://www.sphinxsearch.com/">sphinx mysql plugin</a>). The best thing I could think of were triggers.</p>
<p><strong>What are triggers?</strong></p>
<p>Trigger is simple peace of sql code that is executed when predefined event happens. Most commonly they are used after insert or before insert.</p>
<p><strong>General Idea </strong></p>
<p>I we can&#8217;t have one table with full text and referential integrity then we need two tables one InnoDB and one MyIsam. It would be really stupid to create two identical tables, so I created new MyIsam table with only those columns I wanted to search and key which connects these two tables.<br />
After this I needed a After Insert Trigger to execute so both tables would have identical content. Problem with this is that MySQL introduced triggers in version 5, which is still considered to be an very exotic peace of software.</p>
<p>Here is a sample Before Insert trigger:</p>
<pre lang="sql" name="code">mysql&gt; CREATE TRIGGER test
-&gt; AFTER INSERT ON t
-&gt; FOR EACH ROW
-&gt; BEGIN
-&gt;   INSERT INTO test2 SET column1 = NEW.column1;
-&gt;   INSERT INTO test3 SET column1 = NEW.column1 + 4;
-&gt;   END;//
Query OK, 0 rows affected (0.00 sec)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/databases/fulltext-boolean-search-on-innodb/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How-to: Full text search in MySQL</title>
		<link>http://www.hazaah.com/databases/mysql/fulltext-search-mysql/</link>
		<comments>http://www.hazaah.com/databases/mysql/fulltext-search-mysql/#comments</comments>
		<pubDate>Wed, 29 Nov 2006 14:11:38 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/vladimir-cvetic/databases/mysql/fulltext-search-mysql/</guid>
		<description><![CDATA[MySQL has had FULLTEXT searching in one form or another since version 3.23.23. FULLTEXT indices in MySQL allow database administrators and programmers to designate any character-based field (CHAR, VARCHAR, or TEXT) as a FULLTEXT index, which allows for complex text searching against data stored in those fields.
This feature is not to be confused with the [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL has had FULLTEXT searching in one form or another since version 3.23.23. FULLTEXT indices in MySQL allow database administrators and programmers to designate any character-based field (CHAR, VARCHAR, or TEXT) as a FULLTEXT index, which allows for complex text searching against data stored in those fields.</p>
<p>This feature is not to be confused with the LIKE function in MySQL. LIKE works more along the lines of a regular expression. On the other hand, FULLTEXT indices are fully indexed fields which support stopwords, boolean searches, and relevancy ratings.</p>
<p><strong>How does it work ?</strong></p>
<p>Adding Full Text to your table is very easy it will remind you of adding regular keys or indexes. We will begin with creating a simple news table and fill it with some content:</p>
<pre lang="sql">CREATE TABLE news
(
ID INT(9) UNSIGNED NOT NULL DEFAULT '0' AUTO_INCREMENT,
title CHAR(255) NOT NULL DEFAULT '',
body TEXT NOT NULL DEFAULT '',
PRIMARY KEY (ID),
FULLTEXT(title,body)
);

INSERT INTO news
VALUES (1,
'Pellentesque mauris',
'Pellentesque mauris turpis, porta vel, euismod sed,
pulvinar vitae, tortor. Duis accumsan. Suspendisse facilisis blandit mauris.');

INSERT INTO news
VALUES (2,
'Mauris eu massa',
'Praesent varius orci sit amet erat. Suspendisse sed quam non sapien
consectetuer scelerisque. Aliquam mauris pede, vestibulum vitae,
dapibus vel, cursus at, sapien. Nullam vel purus sit amet quam placerat
suscipit.');

INSERT INTO news
VALUES (3,
'Cum sociis',
'Ut auctor eleifend magna. Morbi porttitor, felis nec accumsan
elementum, lectus justo interdum sapien, non volutpat felis est quis
felis. Vestibulum nulla.');

INSERT INTO news
VALUES (4,
'Quisque dolor!',
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed sapien
nunc, feugiat et, ultrices eget, aliquam non, nulla. Cras mollis. Duis
eget eros. In mauris. Mauris purus massa, mollis at, malesuada in,
vulputate vitae, odio. Duis ut dolor. Phasellus id nunc non est dictum
porttitor.');</pre>
<p><strong>Getting results</strong></p>
<p>Now that we have filled our table with some news we can start doing some queries.</p>
<pre lang="sql">SELECT ID,title
FROM news
WHERE MATCH (title,body) AGAINST('sociis');</pre>
<p>Ok this is simplest full text search query. There are few things you must know tho.<br />
Columns in match() must always be the same ones that we defined as fulltext.</p>
<p>With fulltext you will get results sorted by their relevance aka score, lets display that score.</p>
<pre lang="sql">SELECT ID,title
FROM news
WHERE MATCH (title,body) AGAINST('sociis') as score;</pre>
<p>Using full text search doesn&#8217;t not forbid you to use other sql statements, for example limit etc.</p>
<p><strong>Boolean mode</strong></p>
<pre lang="sql">SELECT ID,title
FROM news
WHERE MATCH (title,body) AGAINST('+sed -mauris') as score;</pre>
<p>You can filter results given by searching with boolean query. Look at against(), you will notice + and &#8211; signs in front of keywords, + sign means that word will be included in search and minus sign means that all results containing this keyword will be excluded from search.</p>
<p>And at the end I must warn you that Full Text search is not supported on InnoDB table engine. (so referential integiry and full text don&#8217;t stack)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/databases/mysql/fulltext-search-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Oracle pagination</title>
		<link>http://www.hazaah.com/databases/simple-oracle-pagination/</link>
		<comments>http://www.hazaah.com/databases/simple-oracle-pagination/#comments</comments>
		<pubDate>Wed, 22 Nov 2006 11:36:27 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/vladimir-cvetic/something-else/simple-oracle-pagination/</guid>
		<description><![CDATA[Alot of folks have problems when they first transfer to Oracle from MySQL.
Most of those problems are cosed by absence of LIMIT.
Just to give you all a hint in the right direction here is the simplest &#8220;pagination&#8221; query used on Oracle.
(select * from emp
where rownum ]]></description>
			<content:encoded><![CDATA[<p>Alot of folks have problems when they first transfer to Oracle from MySQL.<br />
Most of those problems are cosed by absence of LIMIT.</p>
<p>Just to give you all a hint in the right direction here is the simplest &#8220;pagination&#8221; query used on Oracle.</p>
<pre lang="sql">(select * from emp
where rownum <=var)
minus
(select * from emp
where rownum<=(var-100))</pre>
<p>ex.<br />
var = 100 Will give first 100 results and var = 200 will give next 100 results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/databases/simple-oracle-pagination/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Strict Date validation for Oracle</title>
		<link>http://www.hazaah.com/databases/strict-date-validation-for-oracle-isdate-replacement/</link>
		<comments>http://www.hazaah.com/databases/strict-date-validation-for-oracle-isdate-replacement/#comments</comments>
		<pubDate>Tue, 21 Nov 2006 09:09:57 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/admin/databases/strict-date-validation-for-oracle-decent-isdate-replacement/</guid>
		<description><![CDATA[We had few problems with a huge database table (1600k rows of data). Basically problem was with invalid dates.
Our database is receiving data over serial port so there was Alot of garbage. Sice it&#8217;s such a huge table and there was so much invalid date formats I was forced to create decent Oracle replacement for [...]]]></description>
			<content:encoded><![CDATA[<p>We had few problems with a huge database table (1600k rows of data). Basically problem was with invalid dates.</p>
<p>Our database is receiving data over serial port so there was Alot of garbage. Sice it&#8217;s such a huge table and there was so much invalid date formats I was forced to create decent Oracle replacement for VB function IsDate:</p>
<pre lang="sql">CREATE FUNCTION ISDATE( ip_date in varchar2 )
return date
is
begin
return to_date(ip_date,'dd-mm-yyyy');
exception
when others
then return null;
end isdate;</pre>
<p>Only flaw I found was that you need to predefine date type you need&#8230; but we already knew that so it was not a problem.</p>
<p>Hope this helps someone!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/databases/strict-date-validation-for-oracle-isdate-replacement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>2nd part Referential integrity with MySQL</title>
		<link>http://www.hazaah.com/databases/2-deo-referencijalni-interitet-u-mysql-bazama-podataka/</link>
		<comments>http://www.hazaah.com/databases/2-deo-referencijalni-interitet-u-mysql-bazama-podataka/#comments</comments>
		<pubDate>Tue, 14 Nov 2006 11:10:56 +0000</pubDate>
		<dc:creator>Vladimir Cvetic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.knowbies.com/vladimir-cvetic/databases/2-deo-referencijalni-interitet-u-mysql-bazama-podataka/</guid>
		<description><![CDATA[In first part I talked about the basis of referential integrity, in this part I will go through few practical examples.
For start we will create on table that we will call â€˜newsâ€™ and then insert few rows
CREATE TABLE news (id TINYINT NOT NULL AUTO_INCREMENT,
title VARCHAR(50), body VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE=INNODB;
Query OK, 0 rows [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.knowbies.com/vladimir-cvetic/databases/1-deo-referencijalni-integritet-u-mysql-bazama-podataka/">first part</a> I talked about the basis of referential integrity, in this part I will go through few practical examples.<br />
For start we will create on table that we will call â€˜newsâ€™ and then insert few rows</p>
<pre lang="sql">CREATE TABLE news (id TINYINT NOT NULL AUTO_INCREMENT,
title VARCHAR(50), body VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE=INNODB;
Query OK, 0 rows affected (0.11 sec)

INSERT INTO novosti VALUES (1, 'Some title, 'Testing body'), (2, 'Another title', 'Again some body for news');
Query OK, 4 rows affected (0.06 sec)
Records: 4  Duplicates: 0  Warnings: 0</pre>
<p>To show example of referential integrity we will create another table called â€˜commentsâ€™</p>
<pre lang="sql">CREATE TABLE comments (
id INT(4) NOT NULL,
title VARCHAR(50) NOT NULL,
comment VARCHAR(255) NOT NULL,
id_news TINYINT(4) NOT NULL,
INDEX (id_news),
FOREIGN KEY (id_news) REFERENCES novosti (id),
PRIMARY KEY(id)
) ENGINE=INNODB;</pre>
<p>In table comments we defined foreign key id_news and referred it to id field in table news. I we tried to insert random rows in comments table it would look something like this:</p>
<pre lang="sql">INSERT INTO comments VALUES (1, 'Comment title', 'Some comment text', 91);
ERROR 1216 (23000): Cannot add or update a child row: a foreign key
constraint fails</pre>
<p><strong>Note: </strong>look at first and last value of this insert, note that it does not match any news so this comment would be just junk data.<br />
So we are protected on database level from junk data. Even tho this is highly recommended donâ€™t try to dump your application level validation, since you need error handling (so you users donâ€™t get ugly errors) and also mysql is not able to validate data for example E-mail addresses.</p>
<p>Hope it helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hazaah.com/databases/2-deo-referencijalni-interitet-u-mysql-bazama-podataka/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
