<?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>Master for Webs &#187; MySQL</title>
	<atom:link href="http://master4webs.com/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://master4webs.com</link>
	<description>All tools for web masters</description>
	<lastBuildDate>Sun, 02 Oct 2011 08:08:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Migrating MySQL to PostgreSQL</title>
		<link>http://master4webs.com/migrating-mysql-to-postgresql.html</link>
		<comments>http://master4webs.com/migrating-mysql-to-postgresql.html#comments</comments>
		<pubDate>Sat, 16 Oct 2010 04:22:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[database Source]]></category>
		<category><![CDATA[migration database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://master4webs.com/?p=4616</guid>
		<description><![CDATA[This time we continue to see the tools provided in this suite of free software, is now the turn to introduce the use of a new application llamdo Migration Wizard as the name suggests enables a clean migration database implemented in MySQL to another database implemented in PostgreSQL, if as you read, this is aspirin [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This time we continue to see the tools provided in this suite of free software, is now the turn to introduce the use of a new application llamdo Migration Wizard as the name suggests enables a clean migration database implemented in MySQL to another database implemented in PostgreSQL, if as you read, this is aspirin to relieve headache that makes us take a database implemented and managed by the MySQL database server, and is on its total transformation into a secure database implemented and managed by the PostgreSQL database server. <span id="more-4616"></span></p>
<p style="text-align: justify;">Exist in the market and everyone in the Web many solutions already developed that perform the same operation, some are complex script programming languages made rare for most people who work with Windows, I mean perls, python, ruby, bash , among others, it is also true that the vast majority of friendly applications that perform this task are proprietary, they have expensive plans, acquisition and use, but never too late to the computer world, when you do not see the exit only have to cling to what little light is left and wait for the spark is lit either by us or by the huge community of free software developers.</p>
<p style="text-align: justify;">Migration Wizard is developed with the popular Java programming language, pose a very simple desktop interface that is guiding us for 7 short steps for the implementation of the Migration.</p>
<p style="text-align: justify;">The first thing is to start the application from the group of tools that were installed with the suite EnterpriseDB.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database.jpg"><img class="aligncenter size-medium wp-image-4617" title="database" src="http://master4webs.com/wp-content/uploads/2010/10/database-251x300.jpg" alt="" width="251" height="300" /></a></p>
<p style="text-align: justify;">The application starts and his first window indicates that you configure the data connection to MySQL server, which in this case is the source DB which we wish to migrate, including the necessary data is ask include:</p>
<ul style="text-align: justify;">
<li>The server (host) where the server running MySQL, in my case, the server is running on the local machine (localhost), which means that the application Migration Wizard and MySQL are running on the same computer.</li>
<li>The network port on the MySQL server connection is taking applications customers are interested in them do any transaction relating to any database, by default MySQL uses port 3306 to connect with customers who ask for the execution of an operation.</li>
<li>The name of the source database (which you want to migrate to PostgreSQL), which in our case is the quejasyreclamos database, database I have previously created for an article on development of desktop applications with Java, the which this case ready.</li>
<li>The user ID of the MySQL server that has privileges on the source database (quejasyreclamos in our case), I have placed the root user is the administrator who creates MySQL by default during the collation process, the user has privileges on all databases deployed on MySQL</li>
<li>The password of the database Source, in my case I have not put password simply because I have not even put your root password</li>
</ul>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-1.jpg"><img class="aligncenter size-medium wp-image-4618" title="database 1" src="http://master4webs.com/wp-content/uploads/2010/10/database-1-300x180.jpg" alt="" width="300" height="180" /></a></p>
<p style="text-align: justify;">If we provide the data correctly, pressing the Next button will display the window on the second step, this step must tell the application which is the data connection to the target PostgreSQL server (on which will migrate from the base source data), data to be provided are:</p>
<ul style="text-align: justify;">
<li>The server (host) where the server running PostgreSQL in my case, the server is running on the local machine (localhost), which means that the application Migration Wizard, the MySQL server and PostgreSQL server are running on the same computer.</li>
<li>The network port to PostgreSQL server connections is taking applications customers are interested in them perform an operation related to any database, PostgreSQL uses the default port 5432 to connect with customers who ask for the execution of an operation.</li>
<li>The name of the target database (which was implemented on the migration of the source database), which in our case is the quejasyreclamos database.</li>
<li>The user ID the PostgreSQL server that has privileges on the source database (quejasyreclamos in our case), I placed the user postgres is the PostgreSQL administrator created by default during the collation process, the user has privileges on all databases implemented on PostgreSQL</li>
<li>The password of the database origin, unlike MySQL, PostgreSQL requires that each user created on your system, you provide a password from the moment of its creation.</li>
</ul>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-2.jpg"><img class="aligncenter size-medium wp-image-4619" title="database 2" src="http://master4webs.com/wp-content/uploads/2010/10/database-2-300x150.jpg" alt="" width="300" height="150" /></a></p>
<p style="text-align: justify;">Pressing the button below Migration Wizard provides communication with the PostgreSQL server (if the host, port, username and password are correct) and asks you to let you use the quejasyreclamos database, the PostgreSQL server search inside this BD and not finding it sends the warning message, notifying you that has failed to CoNEXT to the database indicated that simply has not yet been created or was deleted, in my case, I made this way on purpose to show the notification message PostgreSQL sent to any customer who wishes to use a database that does not exist in their schemes.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-3.jpg"><img class="aligncenter size-medium wp-image-4620" title="database 3" src="http://master4webs.com/wp-content/uploads/2010/10/database-3-300x152.jpg" alt="" width="300" height="152" /></a></p>
<p style="text-align: justify;">The above problem is solved by creating the database schema quejasyreclamos as a data base within the PostgreSQL server, there are basically two ways to do this, one is using the postgres console client that comes with the installation of PostgreSQL , but being a script-based client console (Windows or DOS Bash GNU / Linux) is very cumbersome operability and user interface, the other way is to use any of the many graphical clients (desktop or web-like type ) operations developed for PostgreSQL server administration or DML (Data Manipulation Language, select, insert, update, delete, store_procedure and triggers) or DDL (Data Definition Language, create, alter, drop, grant, revoke , store_procedure and triggers) on their databases, these applications are much more comfortable, intuitive and easy-to-use console client application.</p>
<p style="text-align: justify;">When selecting which of the available clients to work with PostgreSQL you use,you always lean towards the option provided by the supplier or developer of database server, as we are talking about PostgreSQL, its developer community has created almost Since its inception application called pgAdmin III, which in my opinion and evaluation, the best choice among all the reasons are many and we think the vast majority of them have no reason to explain.</p>
<p style="text-align: justify;">To use pgAdmin III should be selected from the list of tools that are installed on the PostgreSQL menu.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-4.jpg"><img class="aligncenter size-medium wp-image-4621" title="database 4" src="http://master4webs.com/wp-content/uploads/2010/10/database-4-237x300.jpg" alt="" width="237" height="300" /></a></p>
<p style="text-align: justify;">Graphic graphic interface of this application is very intuitive, can be configured in virtually any language you only need to have basic concepts of databases and pgAdmin III provides all the functionality we needed to work with both the BD engine, which PostgreSQL is our case, as with their own databases it manages.</p>
<p style="text-align: justify;"><strong>A complete database is composed of three parts: </strong></p>
<ul style="text-align: justify;">
<li><strong>Databases:</strong> A collection of files called tables, structured by a storage standard that allows persistent operations (Insert, Modify, Delete and Find) in a very efficient and stable minimizadnos redundancy and inconsistency of information stored in those files. In this example the database is represented by quejasyreclamos</li>
<li><strong>The Database Engine:</strong> A system that defines the work rules, safety and handling of files (tables) and information, running or operation embodies the desire to perform in on stage, define which users can work on the basis data and privileges that they have no on them, among other things no less important. In this example the motor is represented by MySQL or PostgreDQL</li>
<li><strong>System Database Manager:</strong> The DBMS by its Spanish acronym, face towards the user (fontEnd), responsible for display users can perform operations on databases in a transparent, intuitive and secure, offers a Advanced layer of abstraction to the entire technology architecture upon which it is based and implemented database systems. In this example, the DBMS is represented by pgAdmin</li>
</ul>
<p style="text-align: justify;">There are some software that make up the engine and the DBMS in a single product, such as Microsoft Access and Open Oficce Base, while other systems are based upon an architecture called client-server, so that the Database Engine (plays Server role) can interact simultaneously with a large number DBMS (playing the role of client).</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-6.jpg"><img class="aligncenter size-medium wp-image-4622" title="database 6" src="http://master4webs.com/wp-content/uploads/2010/10/database-6-300x182.jpg" alt="" width="300" height="182" /></a></p>
<p style="text-align: justify;">The first operation we must make the application once started pgAdmin III is connect to the Database Engine, normally they need data PosgreSQL server connection, such as IP or hostname of the computer where it is running the server, the user name you want to connect to the server and password, optionally the name of the database on which you want to work.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-7.jpg"><img class="aligncenter size-medium wp-image-4623" title="database 7" src="http://master4webs.com/wp-content/uploads/2010/10/database-7-300x183.jpg" alt="" width="300" height="183" /></a></p>
<p style="text-align: justify;">Established connection to the database server, what follows is to ask the dare of the SMB server to perform the operations we want to the extent of our privileges as a user, what concerns us now is creating a new database quejasyreclamos called PostgreSQL.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-8.jpg"><img class="aligncenter size-medium wp-image-4624" title="database 8" src="http://master4webs.com/wp-content/uploads/2010/10/database-8-300x183.jpg" alt="" width="300" height="183" /></a></p>
<p style="text-align: justify;">pgAdmin III shows an interface where you can specify the characteristics of this new database, such as name, type of encoding, the owner (admin user), restrictions, number of connections allowed simultaneously, where the value -1 is undefined .</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-9.jpg"><img class="aligncenter size-medium wp-image-4625" title="database 9" src="http://master4webs.com/wp-content/uploads/2010/10/database-9-205x300.jpg" alt="" width="205" height="300" /></a></p>
<p style="text-align: justify;">In the SQL tab called us to lodge view the source code of SQL (Structured Query Language), which is the language in which you must speak to the Database Engine.</p>
<ol style="text-align: justify;">
<li>CREATE DATABASE quejasyreclamos</li>
<li>WITH ENCODING = &#8216;UTF&#8217;</li>
<li>CONNECTION LIMIT =- 1;</li>
</ol>
<p style="text-align: justify;">
<p style="text-align: justify;">Saving changes to the DBMS builds the appropriate SQL statement based on our requests, are sent to the database engine to execute and deliver this the sovereign response the result of the operation, then the DBMS presents this information in a format quite understandable.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-10.jpg"><img class="aligncenter size-medium wp-image-4626" title="database 10" src="http://master4webs.com/wp-content/uploads/2010/10/database-10-300x201.jpg" alt="" width="300" height="201" /></a>Created target database, we continue to step 3 of the migration process in this step we are asked to provide the format of the dates and type of migration is desired, which may be complete, only the structure of the bases data or only data from the database.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-11.jpg"><img class="aligncenter size-medium wp-image-4627" title="database 11" src="http://master4webs.com/wp-content/uploads/2010/10/database-11-300x152.jpg" alt="" width="300" height="152" /></a></p>
<p style="text-align: justify;">In step # 4 the migration wizard shows the databases found on database engine MySQL, which will allow us to choose the databases that will migrate to the target database PostgreSQL quejasyreclamos, if we choose more than a database, the migration process would export the whole scheme of databases into a single schema belonging to the target database, in other words, the target database will consist of all the elements that structure to each of the origin database.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-12.jpg"><img class="aligncenter size-medium wp-image-4628" title="database 12" src="http://master4webs.com/wp-content/uploads/2010/10/database-12-295x300.jpg" alt="" width="295" height="300" /></a>In step # 5 to select the source database quejasyreclamos which is what concerns us in this paper, the migration wizard shows all the tables that make up this database, allowing us to select which of them will be those that will be part migration.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-13.jpg"><img class="aligncenter size-medium wp-image-4629" title="database 13" src="http://master4webs.com/wp-content/uploads/2010/10/database-13-300x151.jpg" alt="" width="300" height="151" /></a></p>
<p style="text-align: justify;">In step # 6 you can see specific details of the migration process</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-14.jpg"><img class="aligncenter size-medium wp-image-4630" title="database 14" src="http://master4webs.com/wp-content/uploads/2010/10/database-14-300x151.jpg" alt="" width="300" height="151" /></a></p>
<ol style="text-align: justify;">
<li>Source DATABASE connectivity info &#8230;</li>
<li>conn = jdbc: mysql: / / localhost: 3306 / quejasyreclamos</li>
<li>user = root</li>
<li>=****** password</li>
<li>DATABASE connectivity Target info &#8230;</li>
<li>conn = jdbc: edb: / / localhost: 5432 / quejasyreclamos</li>
<li>user = postgres</li>
<li>=****** password</li>
<li>Importing mysql schema &#8230;</li>
<li>Creating Schema &#8230; quejasyreclamos</li>
<li>Migrating Schema TABLES FOR quejasyreclamos &#8216;people&#8217;, &#8216;complaints&#8217;, &#8216;user&#8217;</li>
<li>Creating TABLES &#8230;</li>
<li>Creating TABLE: quejasyreclamos. People</li>
<li>Creating TABLE: quejasyreclamos. Complaints</li>
<li>Creating TABLE: quejasyreclamos. User</li>
<li>Created 3 TABLES.</li>
<li>Loading DATA IN TABLE 8 MB batches &#8230;</li>
<li>Loading TABLE: People &#8230;</li>
<li>Error Loading DATA INTO TABLE: People: Value &#8217;0000-00-00 &#8216;can NOT Be Represented AS Java. Sql. Date</li>
<li>Loading TABLE: Complaints &#8230;</li>
<li>LOAD DATA TABLE Summary: Total Time (s): 0. 109 Total Rows: 0</li>
<li>Loading TABLE: user &#8230;</li>
<li>LOAD DATA TABLE Summary: Total Time (s): 0. 063 Total Rows: 0</li>
<li>Trying to reload TABLE: people-through bulk inserts WITH a batch size of 1000</li>
<li>Error Loading DATA INTO TABLE: people: NULL</li>
<li>LOAD DATA Summary: Total Time (sec): 0. 172 Total Rows: 0 Total Size (MB): 0. 0</li>
<li>Creating Constraint: PRIMARY</li>
<li>Creating Constraint: PRIMARY</li>
<li>Creating Constraint: PRIMARY</li>
<li>One or more schema objects Could not be imported DURING the migration process. Please review the migration output for more details.</li>
</ol>
<p style="text-align: justify;">Step # 7 finish the whole process and we see a reported message service or software support.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-15.jpg"><img class="aligncenter size-medium wp-image-4631" title="database 15" src="http://master4webs.com/wp-content/uploads/2010/10/database-15-300x151.jpg" alt="" width="300" height="151" /></a></p>
<p style="text-align: justify;">Now to see if everything went as we ask, we can return to the DBMS PgAdmin to see the outline of the new database engine quejasyreclamos within PostgreSQL.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-17.jpg"><img class="aligncenter size-medium wp-image-4632" title="database 17" src="http://master4webs.com/wp-content/uploads/2010/10/database-17-300x218.jpg" alt="" width="300" height="218" /></a></p>
<p style="text-align: justify;">Here you can see that the target database PostgreSQL quejasyreclamos pose the whole structure of the source database.</p>
<p style="text-align: justify;"><a href="http://master4webs.com/wp-content/uploads/2010/10/database-18.jpg"><img class="aligncenter size-medium wp-image-4633" title="database 18" src="http://master4webs.com/wp-content/uploads/2010/10/database-18-300x206.jpg" alt="" width="300" height="206" /></a></p>
<p style="text-align: justify;">
]]></content:encoded>
			<wfw:commentRss>http://master4webs.com/migrating-mysql-to-postgresql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Paid on the Web</title>
		<link>http://master4webs.com/getting-paid-on-the-web.html</link>
		<comments>http://master4webs.com/getting-paid-on-the-web.html#comments</comments>
		<pubDate>Tue, 24 Aug 2010 04:38:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[E-Business]]></category>
		<category><![CDATA[Getting Paid]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[the Web]]></category>

		<guid isPermaLink="false">http://master4webs.com/?p=4457</guid>
		<description><![CDATA[You still find it hard to believe, but after that recent trip to the mountains, something that you thought was dead has been reborn! The creative spark! Yes, it&#8217;s back, that tingly urge to craft, build, and endlessly modify, that very special feeling you thought had vanished for good after you failed &#8220;Art 101: Drawing [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">You still find it hard to believe, but after that recent trip to the mountains, something that you thought was dead has been reborn! The creative spark! Yes, it&#8217;s back, that tingly urge to craft, build, and endlessly modify, that very special feeling you thought had vanished for good after you failed &#8220;Art 101: Drawing and Sketching.&#8221; And now, after weeks locked in your studio — the light-deprived cube that your friends still refer to as your bedroom — you have created a small but appealing collection of objects de art (maybe sculpture, maybe music, maybe both!). Next step? Find a way to sell your fiery ingots of love.<span id="more-4457"></span></p>
<p style="text-align: justify;">With local galleries too narrow-minded (obviously!) to appreciate your work, you turn the Internet, really the best and most far-reaching distribution network out there. You take all the obvious steps: Build a site, take some photos, write descriptions, ZIP your files, encode your songs into MP3 and ready them for download. But what happens when somebody visits your site, likes what they see and hear, and wants to purchase one of your creations? Are you ready to dip your toe into the chilly waters of e-biz?</p>
<p style="text-align: justify;">Whether you&#8217;re selling jewelry or you&#8217;re just a programmer out to make some spending money on the side, the transfer of funds from them to you is a big step. And that&#8217;s our topic for today — getting paid.</p>
<p style="text-align: justify;">Of course, there are several different ways to receive funds online. Of course you can travel down the time-consuming-yet-intellectually-rewarding path of building your own shopping cart. Use Perl, ColdFusion, or transactional databases in MySQL, and you&#8217;re quite literally in business. But if you don&#8217;t have programming muscles to flex, let alone the time to build something yourself, why not set up shop with a Web storefront service? When moving currency from one party to another is involved, options are never hard to come by, and the time, money, and craftiness you need to implement them varies.</p>
<p style="text-align: justify;">But what if you&#8217;re short on resources? Or you don&#8217;t have actual tangible items to sell? Maybe you want to accept donations for a free content service, collect payments for downloaded MP3s, or set up a payment system for a piece of software or Web-based application. Since no hard goods are exchanged — no shipping costs or taxes to calculate, no inventory being moved — simple cash payments may be the best answer.</p>
<p style="text-align: justify;">If you do have actual trinkets to sell, hosting a third-party shopping cart on your site is also an option. Third-party shopping cart solutions are easy to put into action just by filling out a few forms and plugging in a credit card number (yours). However, since your users actually have go log in to a different and unfamiliar site when they want to purchase something, third-party shopping carts don&#8217;t provide your customers with a seamless shopping experience. Also, many of these systems require you to set up a merchant account. Merchant accounts, which we&#8217;ll look at in depth later, are tied to major financial institutions, so there are fees involved. The fees you pay for these all-inclusive systems will dramatically increase your overhead if you&#8217;re strictly small-scale. So if you&#8217;re still in mom-and-pop land, cash payments are the most economical and the easiest.</p>
<p style="text-align: justify;">Cash payments on the Internet involve the transfer of funds from one person&#8217;s bank or credit card account to another person&#8217;s account. It&#8217;s the same basic idea as sending a check through the mail, except a Web payment is faster, easily trackable, and more secure. These types of low-level e-commerce, different from the more complex world of shopping carts and inventory management, are sometimes called &#8220;e-cash payments.&#8221; Several companies have developed payment systems that you can use either on a one-off basis, as a subscriber, or as a full-fledged credit merchant. Each service has its advantages and hang-ups, which is just what we&#8217;ll be looking at as we examine a variety of services in the pages that follow.</p>
<p style="text-align: justify;">In addition to cash payment services, we&#8217;ll be cracking open e-wallet systems, as well as the aforementioned third-party shopping cart and merchant account services. I&#8217;ve rated all of these services based not only on their usability and coolness factors, but also on whether their sites clearly offered all the vital bits of info (security statements, fee schedules, and terms of use statements) — it&#8217;s difficult to trust a company that doesn&#8217;t provide all the facts right up front. Note that the list of services I chose to profile is by no means comprehensive. If you plan to use cash payments, I encourage you to follow up what you learn today with some research of your own before committing to a choice.</p>
<p style="text-align: justify;">Let&#8217;s start with simple cash payments. There&#8217;s a company which I&#8217;m sure many of you are familiar with that handles millions of dollars in transactions per day. It&#8217;s called PayPal.</p>
]]></content:encoded>
			<wfw:commentRss>http://master4webs.com/getting-paid-on-the-web.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QUERY and the Database</title>
		<link>http://master4webs.com/query-and-the-database.html</link>
		<comments>http://master4webs.com/query-and-the-database.html#comments</comments>
		<pubDate>Fri, 26 Jun 2009 12:46:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[QUERY]]></category>
		<category><![CDATA[QUERY synopsis]]></category>

		<guid isPermaLink="false">http://master4webs.com/?p=100</guid>
		<description><![CDATA[Not needing a SQL database for every site or every table means you can use Interchange in more hosting environments, but that&#8221;s has usually come at the cost of being able to use SQL as your query language. Fortunately Interchange comes with a built-in SQL interpreter, which means you can use a single query language [...]]]></description>
			<content:encoded><![CDATA[<p>Not needing a SQL database for every site or every table means you can use Interchange in more hosting environments, but that&#8221;s has usually come at the cost of being able to use SQL as your query language. Fortunately Interchange comes with a built-in SQL interpreter, which means you can use a single query language even if your tables are stored in a &#8220;flat file&#8221; instead of something like MySQL or Oracle. <span id="more-100"></span></p>
<p>The QUERY tag is the main interface for executing arbitrary SQL on any table, regardless of the back-end.</p>
<h2>QUERY synopsis</h2>
<pre>[query
	list="1"
	sql="SELECT * FROM products WHERE prod_group = 'Toys'"]

	&lt;li&gt;[sql-param description] - [price [sql-code]]&lt;/li&gt;

[/query]</pre>
<h3>Step 1</h3>
<p>QUERY is a container tag surrounding code that&#8217;s repeated for each row returned by the query, so it always has a closing tag.</p>
<h3>Step 2</h3>
<p>Passing <code>list="1"</code> tells Interchange that you&#8217;re expecting a &#8220;list&#8221;&#8211;or multiple rows, in other words. If you don&#8221;t pass this, the code surrounded by the QUERY tags won&#8221;t be executed. You need to pass this even if you&#8221;re only expecting one row in the results.</p>
<p>If you remember that &#8220;SELECT is a LIST&#8221; it won&#8221;t be a problem. But the QUERY tag is versatile enough that you can also run UPDATE and INSERT queries, and for these you can omit the <code>list="1"</code> parameter. You&#8217;ll still need a closing QUERY tag, though.</p>
<h3>Step 3</h3>
<p>The actual query is passed in the <code>sql="SELECT..."</code> parameter. From within here you can also use other Interchange tags, such as SCRATCH. Remember to quote anything, where necessary, like this:</p>
<pre>[query
	list="1"
	sql="SELECT * FROM products WHERE prod_group = '[scratch prod_group]'"]

	... your code here ...

[/query]</pre>
<p><strong>Security warning:</strong> It&#8217;s tempting to pass user input in some form when creating queries. Writing <code>prod_group='[CGI prod_group]'</code> is a quick and easy way to start a search results page, but it can be exploited by a hacker, who could pass something like this:</p>
<pre>	foo'; delete from products where sku != '</pre>
<p>In this example, the ending quote and semicolon after <code>foo</code> closes the WHERE clause of the first query and then closes the query. The following query can then be executed, deleting all the products in your store. The code reading <code>where sku != '</code> just makes sure there&#8217;s no syntax error that&#8217;d otherwise stop his malicious query from running.</p>
<p>To avoid accidents like this, you can screen incoming user data for quote marks and save the result in a scratch variable, like this:</p>
<pre>[tmp prod_group][calc]
	my $group = $CGI-&gt;{prod_group};
	$group =~ s/'/''/g;
	return $group;
[/calc][/tmp]</pre>
<p>The perl code here is substituting each single quote for a <em>pair</em> of single quotes (that&#8217;s not a double quote there, it&#8217;s two singles), which is how most SQL databases encode the quote character for use within strings passed to queries. With that in place, the hacker can&#8217;t get a malicious query to run, because he can&#8217;t break out of the first. In the worst case, the query would simply fail rather than delete all of your products.</p>
<p><strong>You should always screen form-submitted data</strong> even if you&#8217;re passing it through hidden variables, or SELECT lists that constrain the input. None of these methods stop a hacker from contriving a GET or POST form submission with whatever he likes.</p>
<h3>Step 4</h3>
<p>The code to be run for each row of results is interpolated for SQL tags. The first useful tag is SQL-PARAM, which lets you pull any column from the results, even computed, virtual or renamed columns. For example:</p>
<pre>[query
	list="1"
	sql="SELECT sku,description,
		date_format(entered,'%Y-%m-%d') as added,
		price + 10 as compare
		FROM products"]

	&lt;li&gt;[sql-param description] added [sql-param added]
		- [price [sql-code]] (compare to $[sql-param compare])&lt;/li&gt;

[/query]</pre>
<h2>Advanced</h2>
<h3>ON-MATCH and NO-MATCH</h3>
<p>Like with Interchange&#8217;s tags for summarizing search results, QUERY also understands the ON-MATCH and NO-MATCH tags to display something once when it finds rows, or doesn&#8217;t.</p>
<pre>[query
	list="1"
	sql="SELECT * FROM products WHERE prod_group = '[scratch prod_group]'"]

	[on-match]
		&lt;p&gt;We found the following products for [scratch prod_group].&lt;/p&gt;
		&lt;ul&gt;
	[/on-match]

	[list]
		&lt;li&gt;[sql-param description] - [price [sql-code]]&lt;/li&gt;
	[/list]

	[on-match]
		&lt;/ul&gt;
	[/on-match]

	[no-match]
		&lt;p&gt;Sorry, no matches for [scratch prod_group].&lt;/p&gt;
	[/no-match]

[/query]</pre>
<p>When you use the ON-MATCH or NO-MATCH tags, you imply the use of LIST as well. That&#8217;s because Interchange wouldn&#8217;t otherwise know what part of the code is meant to be repeated for each row.</p>
<p>In this example, there are two ON-MATCH blocks wrapped around the list to open and close a pair of HTML Unordered List tags. But you could also use them to open and close tables, paragraphs, or whatever.</p>
]]></content:encoded>
			<wfw:commentRss>http://master4webs.com/query-and-the-database.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

