<?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"
	>

<channel>
	<title>Gevik's Stuff</title>
	<atom:link href="http://www.truesoftware.net/gevik/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.truesoftware.net/gevik</link>
	<description>My little place on the net</description>
	<pubDate>Mon, 27 Oct 2008 23:00:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>T-DOSE 2008</title>
		<link>http://www.truesoftware.net/gevik/2008/10/t-dose-2008/</link>
		<comments>http://www.truesoftware.net/gevik/2008/10/t-dose-2008/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 23:00:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=31</guid>
		<description><![CDATA[This year’s t-dose meeting was fun. The very young Dutch PostgreSQL community also had a booth where we could answer various question. Personally for me it was very enlightening to see what people are considering when it comes to switching between databases. The majority of question we got was about why one should migrate from [...]]]></description>
			<content:encoded><![CDATA[<p>This year’s <a target="blank" href="http://www.t-dose.org">t-dose</a> meeting was fun. The very young Dutch PostgreSQL community also had a booth where we could answer various question. Personally for me it was very enlightening to see what people are considering when it comes to switching between databases. The majority of question we got was about why one should migrate from other databases (especially MySQL) to PostgreSQL. This triggered some ideas for talks in the future.</p>
<p>I was positively surprised to see a gentleman from the dutch opensource software initiative donating an amount of money to the PostgreSQL EU community.</p>
<p>Here are some photos:</p>
<p><img src="/gevik/images/tdose/2008/P1030839.jpg" alt="" /><br />
<br/><br />
<img src="/gevik/images/tdose/2008/P1030841.jpg" alt="" /><br />
<br/><br />
<img src="/gevik/images/tdose/2008/P1030837.jpg" alt="" /><br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/10/t-dose-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Compiling Qt with native PostgreSQL drivers on Windows XP</title>
		<link>http://www.truesoftware.net/gevik/2008/06/compiling-qt-with-native-postgresql-on-windows-xp/</link>
		<comments>http://www.truesoftware.net/gevik/2008/06/compiling-qt-with-native-postgresql-on-windows-xp/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 23:05:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=13</guid>
		<description><![CDATA[
I spent the last three hours looking and  Googling to solve a very annoying problem in order to compile PostgreSQL drivers natively with Qt 4.4.0 framework. After a lot of frustration I discovered that one has to provide the path to libpq.lib and the PostgreSQL include dir in UNIX style or 8.3 short filenames [...]]]></description>
			<content:encoded><![CDATA[<p>
I spent the last three hours looking and  Googling to solve a very annoying problem in order to compile PostgreSQL drivers natively with Qt 4.4.0 framework. After a lot of frustration I discovered that one has to provide the path to <strong>libpq.lib</strong> and the PostgreSQL include dir in UNIX style or 8.3 short filenames to get the qmake.exe to read them correctly.
</p>
<p>
After running configure.exe, I had to modify <strong>.qmake.cache</strong> like to following to make it work:
</p>
<pre name="code" class="php">
QMAKE_QT_VERSION_OVERRIDE = 4
LIBS           += C:\PROGRA~1\POSTGR~1\8.3\lib\libpq.lib
LIBPATH        += C:\PROGRA~1\POSTGR~1\8.3\lib
INCLUDEPATH    += C:\PROGRA~1\POSTGR~1\8.3\include
OBJECTS_DIR     = tmp\obj\debug_shared
MOC_DIR         = tmp\moc\debug_shared
RCC_DIR         = tmp\rcc\debug_shared
sql-drivers    += odbc psql
sql-plugins    += sqlite
....
....
....
QMAKE_LIBDIR_QT = $$QT_BUILD_TREE\lib
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/06/compiling-qt-with-native-postgresql-on-windows-xp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DROP_TABLE_IF_EXISTS</title>
		<link>http://www.truesoftware.net/gevik/2008/06/drop_table_if_exists/</link>
		<comments>http://www.truesoftware.net/gevik/2008/06/drop_table_if_exists/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 23:17:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=12</guid>
		<description><![CDATA[
In this  post, there is a nice explanation about executing conditional DDL. Here are my two functions which I use when I have to recreate a database schema.


create or replace function table_drop_if_exist(tbl varchar(255)) returns void as
$$
begin
	if (select count(relname) from pg_class where relname=tbl)  0 then
		raise notice &#8216;dropping [%] with cascade&#8217;,tbl;
		execute &#8216;drop table &#8216; &#124;&#124; [...]]]></description>
			<content:encoded><![CDATA[<p>
In this  <a target="_blank" href="http://www.depesz.com/index.php/2008/06/18/conditional-ddl/">post</a>, there is a nice explanation about executing conditional DDL. Here are my two functions which I use when I have to recreate a database schema.
</p>
<pre name="code" class="sql">
create or replace function table_drop_if_exist(tbl varchar(255)) returns void as
$$
begin
	if (select count(relname) from pg_class where relname=tbl) <> 0 then
		raise notice &#8216;dropping [%] with cascade&#8217;,tbl;
		execute &#8216;drop table &#8216; || tbl || &#8216; cascade&#8217;;
	end if;
end;
$$
language plpgsql;
</pre>
<p>and of course</p>
<pre name="code" class="sql">
create or replace function type_drop_if_exist(typ varchar(255)) returns void as
$$
begin
	if (select count(relname) from pg_class where relname=typ and relkind='c') <> 0 then
		raise notice &#8216;dropping [%] with cascade&#8217;,typ;
		execute &#8216;drop type &#8216; || typ || &#8216; cascade&#8217;;
	end if;
end;
$$
language plpgsql;
</pre>
<p>Usage:</p>
<pre name="code" class="sql">
select table_drop_if_exist('tblregion');
create table tblregion
(
	regionid integer primary key not null,
	region varchar(50),
	code varchar(2)
);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/06/drop_table_if_exists/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Synchronizing sequence values upon manual insert.</title>
		<link>http://www.truesoftware.net/gevik/2008/06/synchronizing-sequence-values-upon-manual-insert/</link>
		<comments>http://www.truesoftware.net/gevik/2008/06/synchronizing-sequence-values-upon-manual-insert/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 07:30:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=11</guid>
		<description><![CDATA[Using sequences are common practice in order to have auto numbering  in a PostgreSQL database. The easiest way to create an auto numbered identity field is to use the SERIAL  data type macro.


Here is an example:

CREATE  TABLE customer
(
	customer_id SERIAL NOT NULL PRIMARY KEY,
	name varchar(50)
);



When running this script, PostgreSQL automatically will create a [...]]]></description>
			<content:encoded><![CDATA[<p>Using sequences are common practice in order to have auto numbering  in a PostgreSQL database. The easiest way to create an auto numbered identity field is to use the <i>SERIAL </i> data type macro.
</p>
<p>
Here is an example:</p>
<pre name="code" class="sql">
CREATE  TABLE customer
(
	customer_id SERIAL NOT NULL PRIMARY KEY,
	name varchar(50)
);
</pre>
</p>
<p>
When running this script, PostgreSQL automatically will create a <i>SEQUENCE</i> called <i>customer_id_seq</i> and assign the default value of the <i>customer_id</i> field to the next available value from the sequence. This is done by calling <i>nextval(&#8217;customer_id_seq&#8217;::regclass)</i>.
</p>
<p>
Upon inserting new records in the <i>customer </i>table, the sequence will work just fine as long as you leave the <i>customer_id</i> field alone. In this the sequence will be incremented twice, generating numbers 1 and 2.</p>
<pre name="code" class="sql">
INSERT INTO customer (name) values('Customer 1');
INSERT INTO customer (name) values('Customer 2');
</pre>
</p>
<p>
But what will happen to the next value on our sequence when we explicitly present data to the <i>customer_id </i>field? For example when we are loading data from an external source. </p>
<pre name="code" class="sql">
INSERT INTO customer (customer_id,name) values(3,'Customer 3');
INSERT INTO customer (customer_id,name) values(4,'Customer 4');
INSERT INTO customer (customer_id,name) values(5,'Customer 5');
</pre>
</p>
<p>
As expected the value of <i>customer_id_seq</i> will not increment as we insert data with the example above. This is because <i>nextval(‘customer_id_seq’)</i> will only be triggered when <i>customer_id </i> is <i>NULL</i>.<br />
As expected the value of <i>customer_id_seq</i> will not increment as we explicitly insert data with the example above. It is because <i>nextval(‘customer_id_seq’)</i> will only be triggered when <i>customer_id</i> is <i>NULL</i>. This means when you try to insert another customer record without explicitly providing a unique <i>customer_id</i>, the <i>nextval(‘customer_id_seq’)</i> will incremented to 3 which is already used, resulting a nice duplicate key exception:</p>
<pre name="code" class="sql">

INSERT INTO customer (name) values('Customer 6');

----------------------------------------------------------------------
ERROR:  duplicate key value violates unique constraint "customer_pkey"

********** Error **********

ERROR: duplicate key value violates unique constraint "customer_pkey"
SQL state: 23505
</pre>
</p>
<p>
This can easily break your application unexpectedly.  In  In order to solve this problem we have to synchronize the value of <i>customer_id_seq</i> with the latest value existing in the <i>customer_id</i> column: The following function provides just the functionality needed. Just provide the table name and the the name of the identity column which the sequence is bound to.</p>
<pre name="code" class="sql">
CREATE OR REPLACE FUNCTION sync_sequence(
		table_name VARCHAR,idfield VARCHAR)
		RETURNS VOID AS
$$
DECLARE
	max_id BIGINT;
BEGIN
	-- retriving max id from table_name
	EXECUTE 'select max(' || idfield || ') from '
		|| table_name into max_id;
	-- resetting the default sequence on table_name
	EXECUTE 'alter sequence ' || table_name || '_' ||
		idfield || '_seq restart with ' || (max_id+1);
END;
$$
LANGUAGE PLPGSQL;
</pre>
<pre name="code" class="sql">
SELECT sync_sequence('customer','customer_id');
</pre>
</p>
<p>
Have fun with PostgreSQL <img src='http://www.truesoftware.net/gevik/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/06/synchronizing-sequence-values-upon-manual-insert/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PRADO Component Framework for PHP 5</title>
		<link>http://www.truesoftware.net/gevik/2008/06/prado-component-framework-for-php-5/</link>
		<comments>http://www.truesoftware.net/gevik/2008/06/prado-component-framework-for-php-5/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 12:45:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PRADO Framework]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=10</guid>
		<description><![CDATA[On of the greatest developments in the world of PHP programming, is the evolution of PRADO Framework. I stumbled on this unbelievably powerful and complete framework in 2005 when I was looking for an application development framework on top of PHP.
PRADO unlike other PHP frameworks out there is very much like the good old ASP.NET. [...]]]></description>
			<content:encoded><![CDATA[<p>On of the greatest developments in the world of PHP programming, is the evolution of PRADO Framework. I stumbled on this unbelievably powerful and complete framework in 2005 when I was looking for an application development framework on top of PHP.</p>
<p>PRADO unlike other PHP frameworks out there is very much like the good old ASP.NET. It is very easy to learn. Most importantly, it is supremely efficient in contrast to raw PHP. Imagine building a DataGrid component with raw PHP, or creating a form that needs to validate user input both when submit button is clicked.</p>
<p><strong><br />
<h3><u>PRADO makes PHP scripts, PHP applications.</u></h3>
<p></strong></p>
<pre name="code" class="xml">
&lt;html&gt;
  &lt;body&gt;
    &lt;com:TForm&gt;
      &lt;com:TButton Text="Click me" OnClick="buttonClicked" /&gt;
    &lt;/com:TForm&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<pre name="code" class="php">class Home extends TPage
{
    public function buttonClicked($sender,$param)
    {
        // $sender refers to the button component
        $sender-&gt;Text="Hello World!";
    }
}</pre>
<p>
With a nice separation of markup and code and a resemblance to ASP.NET, having the power of PHP combined, makes PRADO <i>the</i> choice to develop application using<br />
PHP language.
</p>
<p>
At the time of writing this entry PRADO version 3.1.2 released. As you might except in a modern application programming framework for web, PRADO has built-in AJAX support. Most of the standard controls (like Button, DropDown, List) are also AJAX aware.
</p>
<p>
Checkoput the <a target="_blank" href="http://www.pradosoft.com">PRADO website for more</a> information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/06/prado-component-framework-for-php-5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google SyntaxHighlighter</title>
		<link>http://www.truesoftware.net/gevik/2008/06/google-syntaxhighlighter/</link>
		<comments>http://www.truesoftware.net/gevik/2008/06/google-syntaxhighlighter/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 07:55:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=9</guid>
		<description><![CDATA[I was looking for a solution to display source code in way that was readable when posting on my blog. After several failed attempts to format some PHP and SQL code with the PRE tag and CSS styles, I found this nice tool provided by google witch helps you to format/highlight source code on your [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a solution to display source code in way that was readable when posting on my blog. After several failed attempts to format some PHP and SQL code with the PRE tag and CSS styles, I found this nice tool provided by google witch helps you to format/highlight source code on your web pages.</p>
<p>
 <a href="http://code.google.com/p/syntaxhighlighter/">Google SyntaxHighlighter</a>
</p>
<pre name="code" class="sql">
-- Function: new_expiredate()

-- DROP FUNCTION new_expiredate();

CREATE OR REPLACE FUNCTION new_expiredate()
  RETURNS timestamp without time zone AS
$BODY$
	select (date_trunc('month',now()) + interval '7 months')::timestamp without time zone;
$BODY$
  LANGUAGE 'sql' VOLATILE
  COST 100;
ALTER FUNCTION new_expiredate() OWNER TO postgres;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2008/06/google-syntaxhighlighter/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using the CONNECT privilege</title>
		<link>http://www.truesoftware.net/gevik/2006/09/using-the-connect-privilege/</link>
		<comments>http://www.truesoftware.net/gevik/2006/09/using-the-connect-privilege/#comments</comments>
		<pubDate>Fri, 22 Sep 2006 09:36:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=7</guid>
		<description><![CDATA[One of the cool new features in PostgreSQL in the connect privilege. The CONNECT privilege enables you to grant connection rights from a user to a database, avoiding the need to configure user to database access in the pg_hba.conf.
The information in the pg_hba.conf could exclusively be used to administer the authentication (Are you allowed on [...]]]></description>
			<content:encoded><![CDATA[<p>One of the cool new features in PostgreSQL in the connect privilege. The CONNECT privilege enables you to grant connection rights from a user to a database, avoiding the need to configure user to database access in the pg_hba.conf.<br />
The information in the pg_hba.conf could exclusively be used to administer the authentication (Are you allowed on my server?) process and the CONNECT privilege could be used for authorization (What are you allowed to do on my server?)</p>
<p>Let us look at the following scenario:</p>
<p>Imagine you want to enable different users on your network to access different databases on your server. Configuring every user for every permitted database in pg_hba.conf would be time consuming and less administer-friendly. The process could be simplified by allowing a certain network (or subnet) to authenticate and handle the database connection by CONNECT privilege.</p>
<pre name="code" class="sql">
In pg_hba.conf:
# Allow all network users to connect to by server.
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all all 192.168.1.0/24 password

Then secure the databases by:
-- Revoke connection right from all users to main database.
-- Dont worry, the superuser can still connect.
REVOKE CONNECT ON DATABASE postgres FROM PUBLIC;

-- create a new user called joe
CREATE ROLE joe LOGIN;

-- create a new database owned by joe.
CREATE DATABASE customers OWNER joe ENCODING UTF8

-- Revoke connection from everybody on customers database
REVOKE CONNECT ON DATABASE customers FROM PUBLIC;

-- Authorize Joe exclusively to connect to customers database
GRANT CONNECT ON DATABASE customers TO joe;
</pre>
<p>This way only Joe or anyone in that role can connect customers database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2006/09/using-the-connect-privilege/feed/</wfw:commentRss>
		</item>
		<item>
		<title>LIMIT ALL == LIMIT NULL</title>
		<link>http://www.truesoftware.net/gevik/2006/02/limit-all-limit-null/</link>
		<comments>http://www.truesoftware.net/gevik/2006/02/limit-all-limit-null/#comments</comments>
		<pubDate>Thu, 02 Feb 2006 09:39:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.truesoftware.net/gevik/?p=8</guid>
		<description><![CDATA[This maybe trivial but I think it is worth sharing anyway
Consider using LIMIT/OFFSET in a function where as parameter you have to specify values for both.
In the following function both limit and offset parameters are integers. This will cause an error when you want to pass ALL (for LIMIT ALL) as argument.
PostgreSQL function:

create or replace [...]]]></description>
			<content:encoded><![CDATA[<p>This maybe trivial but I think it is worth sharing anyway<br />
Consider using LIMIT/OFFSET in a function where as parameter you have to specify values for both.<br />
In the following function both limit and offset parameters are integers. This will cause an error when you want to pass ALL (for LIMIT ALL) as argument.</p>
<p>PostgreSQL function:</p>
<pre name="code" class="sql">
create or replace function sp_category_getlist
	(plimit integer,poffset integer) returns setof category as
$$
	select *
	from
		category
        order by
		caption
	limit
		$1 offset $2
$$
language sql;
</pre>
<p><strong>Fortunately PostgreSQL accepts NULL function arguments which in this case is treated as ALL</strong></p>
<p>Example in PHP:</p>
<pre name="code" class="php">
/* sp_filesystem_category_getlist */
public function sp_filesystem_category_getlist
	($puserid,$plimit=null,$poffset='0')
{
	$args = array($plimit,$poffset);
	$sql = "select * from sp_filesystem_category_getlist($1,$2)";
	$result=$this-&gt;query($sql,$args);
	return pg_fetch_all($result);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.truesoftware.net/gevik/2006/02/limit-all-limit-null/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
