<?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>Dimuthu's Blog &#187; drupal</title>
	<atom:link href="http://www.dimuthu.org/catagory/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Case Study &#8211; PHP Data Services To Extract Content from Drupal Database</title>
		<link>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/</link>
		<comments>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:40:11 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[case study]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[mashup server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=930</guid>
		<description><![CDATA[In this case study &#8220; PHP Data Services Extract Content from Drupal Database&#8220;, I intended to present how Data Service concepts can be applied to extract data with marketing value from  a CMS database and publish it as web services.  I used the drupal instance deployed at http://wso2.org as the CMS for the use case. [...]]]></description>
			<content:encoded><![CDATA[<p>In this case study &#8220;<a href="http://wso2.org/library/case-studies/case-study-php-data-services-extract-drupal-database"> PHP Data Services Extract Content from Drupal Database</a>&#8220;, I intended to present how Data Service concepts can be applied to extract data with marketing value from  a CMS database and publish it as web services.  I used the drupal instance deployed at <a href="http://wso2.org">http://wso2.org</a> as the CMS for the use case. And as the data service framework, I used <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> data services library, as it requires minimum changes to the existing infrastructure (the LAMP stack).</p>
<p>The case study also talks about how to consume the data service by any third party mashup to present textual/ graphical views of analyzed data. These mashups can be extended up to intergreate with social networks like facebook, twitter and etc to communicate back and forth a wider community and may be it can be used to track the distribution of active users using Google maps. Simply it makes easier to analyze business data + engagement with the community.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AXIOM/C As The XML Object Model</title>
		<link>http://www.dimuthu.org/blog/2008/12/03/using-axiomc-as-the-xml-object-model/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/03/using-axiomc-as-the-xml-object-model/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 16:35:04 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[axiom]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[AXIOM/C]]></category>
		<category><![CDATA[axiom_node_t*]]></category>
		<category><![CDATA[Buffer]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=754</guid>
		<description><![CDATA[In Apache Axis2/C AXIOM is used as the basic object model to represent XML. AXIOM provide a DOM like API that allows to traverse and build the XML very easily. Anyway in underneath, AXIOM is different from DOM, as it has used some techniques to optimize the parsing of the XML as suited specially for [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> AXIOM is used as the basic object model to represent XML. AXIOM provide a DOM like API that allows to traverse and build the XML very easily.</p>
<p>Anyway in underneath, AXIOM is different from DOM, as it has used some techniques to optimize the parsing of the XML as suited specially for SOAP message processing in web services. For an example the SOAP processor can validate a SOAP message by reading only some parts of the SOAP header fields, and if it is not valid, they can completely skip processing the body part. And since AXIOM is designed to built from a stream of data retrieved from a transport, sometimes SOAP processors can validate the message without the need of reading the full stream.</p>
<p>Anyway there should be lot of application that needs this optimization in parsing XMLs. They can easily adapt AXIOM/C to their application. Here is an <a href="http://ws.apache.org/axis2/c/docs/om_tutorial.html">AXIOM/C tutorial</a> that covers both parsing and building XMLs from AXIOM. In this post I&#8217;d like to mention a code that can be used to retrieve an AXIOM from a String (char buffer) which we call as deserialization.</p>
<pre class="c">    axiom_node_t* AXIS2_CALL
    deserialize_my_buffer <span style="color: #66cc66;">(</span>
        <span style="color: #993333;">const</span> axutil_env_t * env,
        <span style="color: #993333;">char</span> *buffer<span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>
        axiom_xml_reader_t *reader = <span style="font-weight: bold; color: #000000;">NULL</span>;
        axiom_stax_builder_t *builder = <span style="font-weight: bold; color: #000000;">NULL</span>;
        axiom_document_t *document = <span style="font-weight: bold; color: #000000;">NULL</span>;
        axiom_node_t *payload = <span style="font-weight: bold; color: #000000;">NULL</span>;

        reader = axiom_xml_reader_create_for_memory <span style="color: #66cc66;">(</span>env,
            buffer, axutil_strlen <span style="color: #66cc66;">(</span>buffer<span style="color: #66cc66;">)</span>,
            AXIS2_UTF_8, AXIS2_XML_PARSER_TYPE_BUFFER<span style="color: #66cc66;">)</span>;

        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!reader<span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
            <span style="color: #b1b100;">return</span> <span style="font-weight: bold; color: #000000;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        builder = axiom_stax_builder_create <span style="color: #66cc66;">(</span>env, reader<span style="color: #66cc66;">)</span>;

        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!builder<span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
            <span style="color: #b1b100;">return</span> <span style="font-weight: bold; color: #000000;">NULL</span>;
        <span style="color: #66cc66;">}</span>
        document = axiom_stax_builder_get_document <span style="color: #66cc66;">(</span>builder, env<span style="color: #66cc66;">)</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!document<span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
            AXIS2_LOG_ERROR <span style="color: #66cc66;">(</span>env-&gt;log, AXIS2_LOG_SI,
                    <span style="color: #ff0000;">"Document is null for deserialization"</span><span style="color: #66cc66;">)</span>;
            <span style="color: #b1b100;">return</span> <span style="font-weight: bold; color: #000000;">NULL</span>;
        <span style="color: #66cc66;">}</span>

        payload = axiom_document_get_root_element <span style="color: #66cc66;">(</span>document, env<span style="color: #66cc66;">)</span>;

        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!payload<span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
            AXIS2_LOG_ERROR <span style="color: #66cc66;">(</span>env-&gt;log, AXIS2_LOG_SI,
                    <span style="color: #ff0000;">"Root element of the document is not found"</span><span style="color: #66cc66;">)</span>;
            <span style="color: #b1b100;">return</span> <span style="font-weight: bold; color: #000000;">NULL</span>;
        <span style="color: #66cc66;">}</span>
        axiom_document_build_all <span style="color: #66cc66;">(</span>document, env<span style="color: #66cc66;">)</span>;

        axiom_stax_builder_free_self <span style="color: #66cc66;">(</span>builder, env<span style="color: #66cc66;">)</span>;

        <span style="color: #b1b100;">return</span> payload;
    <span style="color: #66cc66;">}</span></pre>
<p>Regardless of the fact this piece of code is been used many time by Axis2 and application that uses Axis2, it has never been identified as a core AXIOM function. I think it is better we have this function as an alternative method to create an axiom.</p>
<pre class="c">axiom_node_t *AXIS2_CALL
axiom_node_create_from_buffer<span style="color: #66cc66;">(</span><span style="color: #993333;">const</span> axutil_env_t *env, axis2_char_t *buffer<span style="color: #66cc66;">)</span>;</pre>
<p>I already suggested this in Axis2/C mailing list and hopefully it will be included from the next release.</p>
<p>Here when we create the axiom tree function from the character buffer, we used &#8220;axiom_xml_reader_create_for_memory&#8221; function. Anyway whenever transport read data stream from wire it always uses the &#8220;axiom_xml_reader_create_for_io&#8221; function.</p>
<pre class="c">    <span style="font-style: italic; color: #808080;">/**
     * This create an instance of axiom_xml_reader to
     * parse a xml document in a buffer. It takes a callback
     * function that takes a buffer and the size of the buffer
     * The user must implement a function that takes in buffer
     * and size and fill the buffer with specified size
     * with xml stream, parser will call this function to fill the
     * buffer on the fly while parsing.
     * @param env environment MUST NOT be NULL.
     * @param read_input_callback() callback function that fills
     * a char buffer.
     * @param close_input_callback() callback function that closes
     * the input stream.
     * @param ctx, context can be any data that needs to be passed
     * to the callback method.
     * @param encoding encoding scheme of the xml stream
     */</span>
    AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
    axiom_xml_reader_create_for_io<span style="color: #66cc66;">(</span>
        <span style="color: #993333;">const</span> axutil_env_t * env,
        AXIS2_READ_INPUT_CALLBACK read_callback,
        AXIS2_CLOSE_INPUT_CALLBACK close_callback,
        <span style="color: #993333;">void</span> *ctx,
        <span style="color: #993333;">const</span> axis2_char_t * encoding<span style="color: #66cc66;">)</span>;</pre>
<p>As you may have noticed it requires us to implement a &#8220;read_callback&#8221; function. Here is an example function prototype to implement this callback.</p>
<pre class="c">    <span style="color: #993333;">int</span> AXIS2_CALL
    some_function<span style="color: #66cc66;">(</span>
            <span style="color: #993333;">char</span> *buffer,
            <span style="color: #993333;">int</span> size,
            <span style="color: #993333;">void</span> *ctx<span style="color: #66cc66;">)</span>;</pre>
<p>This function will be called by the parser as required to parse the XML read from some stream.</p>
<p>So if your application involves reading data from a stream you are always recommended to use this function (i.e. &#8220;axiom_xml_reader_create_for_io&#8221;) instead of &#8220;axiom_xml_read_create_for_buffer&#8221; to create the AXIOM model more effectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/03/using-axiomc-as-the-xml-object-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use of MySQL &#8216;GROUP BY&#8217; to Derive Statistics</title>
		<link>http://www.dimuthu.org/blog/2008/11/06/use-of-mysql-group-by-to-derive-statistics/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/06/use-of-mysql-group-by-to-derive-statistics/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 18:49:37 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[GROUP BY]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=579</guid>
		<description><![CDATA[We use &#8216;GROUP BY&#8217; SQL construct to query the data with aggregating some rows according to a field. For an example say if your blog database store your blogs in a table call &#8216;Blog&#8217; and it has &#8216;Date&#8217; as a field. If so SELECT count(*) FROM Blog GROUP BY Date will give you a set [...]]]></description>
			<content:encoded><![CDATA[<p>We use &#8216;GROUP BY&#8217; SQL construct to query the data with aggregating some rows according to a field. For an example say if your blog database store your blogs in a table call &#8216;Blog&#8217; and it has &#8216;Date&#8217; as a field. If so</p>
<pre><span style="font-weight: bold; color: #993333;">SELECT</span> count<span style="color: #66cc66;">(</span>*<span style="color: #66cc66;">)</span> <span style="font-weight: bold; color: #993333;">FROM</span> Blog <span style="font-weight: bold; color: #993333;">GROUP</span> <span style="font-weight: bold; color: #993333;">BY</span> Date</pre>
<p>will give you a set of numbers that represent the number of blog you posted each day.</p>
<pre><span style="font-weight: bold; color: #993333;">SELECT</span> Date, count<span style="color: #66cc66;">(</span>*<span style="color: #66cc66;">)</span> <span style="font-weight: bold; color: #993333;">FROM</span> Blog <span style="font-weight: bold; color: #993333;">GROUP</span> <span style="font-weight: bold; color: #993333;">BY</span> Date</pre>
<p>will give you a map of &#8216;date&#8217; to &#8216;number of blog posted for that date&#8217; without much trouble. <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html"></a></p>
<p>Anyway the problem is most of the databases of blogs don&#8217;t just keep the &#8216;date&#8217; for a blog, rather it keep both &#8216;date and time&#8217; (say in a field called &#8216;Time&#8217;). But you still want to group by date. You may use the MySQL &#8216;DATE&#8217; function to convert the &#8216;Date and Time value&#8217; to just &#8216;Date&#8217; and use it in GROUP BY statement.</p>
<pre><span style="font-weight: bold; color: #993333;">SELECT</span> Date, count<span style="color: #66cc66;">(</span>*<span style="color: #66cc66;">)</span> <span style="font-weight: bold; color: #993333;">FROM</span> Blog <span style="font-weight: bold; color: #993333;">GROUP</span> <span style="font-weight: bold; color: #993333;">BY</span> DATE<span style="color: #66cc66;">(</span>Time<span style="color: #66cc66;">)</span></pre>
<p>If you take Drupal for a blog database, it save the time of the blog entry as a unix timestamp. So you have to derive the Date from the timestamp using the infamous FROM_UNIXTIME mysql function,</p>
<p>In Drupal the database table name to store blog is &#8216;node&#8217; and the field name to store the create time is &#8216;created&#8217; . So your query to get statistics of Drupal would be something like this.</p>
<pre><span style="font-weight: bold; color: #993333;">SELECT</span> DATE<span style="color: #66cc66;">(</span> FROM_UNIXTIME<span style="color: #66cc66;">(</span><span style="color: #ff0000;">`created`</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>, count<span style="color: #66cc66;">(</span>*<span style="color: #66cc66;">)</span>
<span style="font-weight: bold; color: #993333;">FROM</span> <span style="color: #ff0000;">`node`</span>
<span style="font-weight: bold; color: #993333;">GROUP</span> <span style="font-weight: bold; color: #993333;">BY</span> DATE<span style="color: #66cc66;">(</span> FROM_UNIXTIME<span style="color: #66cc66;">(</span><span style="color: #ff0000;">`created`</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span></pre>
<p>Rather than converting the timestamp to SQL Date format, You can convert Date to timestamp and your sql statement may look little mathematical.</p>
<pre class="sql"><span style="font-weight: bold; color: #993333;">SELECT</span> ROUND<span style="color: #66cc66;">(</span> <span style="color: #66cc66;">(</span>
UNIX_TIMESTAMP<span style="color: #66cc66;">(</span> NOW<span style="color: #66cc66;">(</span> <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">)</span> - <span style="color: #ff0000;">`created`</span> <span style="color: #66cc66;">)</span> / <span style="color: #66cc66;">(</span> <span style="color: #cc66cc;">24</span> *<span style="color: #cc66cc;">60</span> *<span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">)</span>, count<span style="color: #66cc66;">(</span> * <span style="color: #66cc66;">)</span>
<span style="font-weight: bold; color: #993333;">FROM</span> <span style="color: #ff0000;">`node`</span>
<span style="font-weight: bold; color: #993333;">GROUP</span> <span style="font-weight: bold; color: #993333;">BY</span> ROUND<span style="color: #66cc66;">(</span> <span style="color: #66cc66;">(</span>
UNIX_TIMESTAMP<span style="color: #66cc66;">(</span> NOW<span style="color: #66cc66;">(</span> <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">)</span> - <span style="color: #ff0000;">`created`</span> <span style="color: #66cc66;">)</span> / <span style="color: #66cc66;">(</span> <span style="color: #cc66cc;">24</span> *<span style="color: #cc66cc;">60</span> *<span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">)</span></pre>
<p>In fact the expression &#8220;UNIX_TIMESTAMP<span style="color: #66cc66;">(</span> NOW<span style="color: #66cc66;">(</span> <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">)</span> &#8211; <span style="color: #ff0000;">`created`</span> <span style="color: #66cc66;">)</span> / <span style="color: #66cc66;">(</span> <span style="color: #cc66cc;">24</span> *<span style="color: #cc66cc;">60</span> *<span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">)</span>&#8221; derives a number that represent the age of the post in days.</p>
<p>So this way you can derive statistics of your data with the use of &#8216;GROUP BY&#8221; construct. The ability to write complex queries in SQL syntax like this is really useful, specially when you access a remote database through a web services (i.e. <a href="http://www.dimuthu.org/tag/data-services/">Data Services</a>) or using database drivers, you have to minimize the number of sql queries to execute as minimum as possible.</p>
<p>Here are some of the other aggregate function that you may use with GROUP BY, <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html">http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/06/use-of-mysql-group-by-to-derive-statistics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
