<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: [PHP::PDO]SQLITE Drop Columns function</title>
	<atom:link href="http://www.taiwangeek.com/2010-08/phppdosqlite-drop-columns-function.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.taiwangeek.com/2010-08/phppdosqlite-drop-columns-function.html</link>
	<description>Time has a wonderful way of showing us what really matters.</description>
	<lastBuildDate>Fri, 01 Apr 2011 18:03:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
	<item>
		<title>By: Sen Sovithia</title>
		<link>http://www.taiwangeek.com/2010-08/phppdosqlite-drop-columns-function.html/comment-page-1#comment-84</link>
		<dc:creator>Sen Sovithia</dc:creator>
		<pubDate>Fri, 01 Apr 2011 18:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.taiwangeek.com/?p=1317#comment-84</guid>
		<description>I give you guys my function to drop a column easily in Sqlite3

function dropColumn($tableName, $columnName)
{
	// YOUR Sqlite file here 
	$base = new SQLite3(&quot;myadmin.sqlite&quot;);
	$query = sprintf(&quot;select sql from sqlite_master where tbl_name = &#039;%s&#039;&quot;, $tableName);
	$res = $base-&gt;querySingle($query,true);
	$sql = $res[&#039;sql&#039;];	
	$s1 = explode(&#039;(&#039;,$sql);
	$s2 = explode(&#039;,&#039;,rtrim($s1[1],&#039;)&#039;));
	$count = 0;
	$colpos = 0;
	//
	$cols = array();
	$colsexpr = array();
	//Recording Field
	foreach($s2 as $expr)
	{
		if (strpos($expr,$columnName))
			$colpos = $count;
		$count++;
		$tmp = explode(&#039; &#039;,trim($expr));
		if ($tmp[0] != $columnName)
		{
			array_push($colsexpr,$expr);
			array_push($cols,$tmp[0]);
		}
	}
	// Preparing Structure
	$sqlCreate = sprintf(&quot;CREATE TABLE %s (&quot;,$tableName);
	foreach ($colsexpr as $colexpr)
		$sqlCreate .= $colexpr . &quot;,&quot;;
	$sqlCreate = rtrim($sqlCreate,&#039;,&#039;);
	$sqlCreate .= &quot;)&quot;;
	// Preparing Data	
	$query2 = sprintf(&quot;select * from %s&quot;,$tableName);
	$datas = $base-&gt;query($query2);
	$inserts = array();
	while($data = $datas-&gt;fetchArray())
	{
		$insert = sprintf(&quot;insert into %s (&quot;,$tableName);
		foreach ($cols as$col)
			$insert .= &quot;&#039;&quot;.$col.&quot;&#039;,&quot;;
		$insert = rtrim($insert,&#039;,&#039;);
		$insert .= &quot;) values (&quot;;
		foreach($cols as $col)
			$insert .= &quot;&#039;&quot;.$data[$col].&quot;&#039;,&quot;;
		$insert = rtrim($insert,&#039;,&#039;);
			$insert .= &quot;)&quot;;
		array_push($inserts,$insert);
	} 
	
	$sqlDrop = sprintf(&quot;drop table %s&quot;,$tableName);
	$base-&gt;exec($sqlDrop);
	$base-&gt;exec($sqlCreate);
	foreach($inserts as $insert)
		$base-&gt;exec($insert);	
	$base-&gt;close();
}</description>
		<content:encoded><![CDATA[<p>I give you guys my function to drop a column easily in Sqlite3</p>
<p>function dropColumn($tableName, $columnName)<br />
{<br />
	// YOUR Sqlite file here<br />
	$base = new SQLite3(&#8220;myadmin.sqlite&#8221;);<br />
	$query = sprintf(&#8220;select sql from sqlite_master where tbl_name = &#8216;%s&#8217;&#8221;, $tableName);<br />
	$res = $base-&gt;querySingle($query,true);<br />
	$sql = $res['sql'];<br />
	$s1 = explode(&#8216;(&#8216;,$sql);<br />
	$s2 = explode(&#8216;,&#8217;,rtrim($s1[1],&#8217;)'));<br />
	$count = 0;<br />
	$colpos = 0;<br />
	//<br />
	$cols = array();<br />
	$colsexpr = array();<br />
	//Recording Field<br />
	foreach($s2 as $expr)<br />
	{<br />
		if (strpos($expr,$columnName))<br />
			$colpos = $count;<br />
		$count++;<br />
		$tmp = explode(&#8216; &#8216;,trim($expr));<br />
		if ($tmp[0] != $columnName)<br />
		{<br />
			array_push($colsexpr,$expr);<br />
			array_push($cols,$tmp[0]);<br />
		}<br />
	}<br />
	// Preparing Structure<br />
	$sqlCreate = sprintf(&#8220;CREATE TABLE %s (&#8220;,$tableName);<br />
	foreach ($colsexpr as $colexpr)<br />
		$sqlCreate .= $colexpr . &#8220;,&#8221;;<br />
	$sqlCreate = rtrim($sqlCreate,&#8217;,');<br />
	$sqlCreate .= &#8220;)&#8221;;<br />
	// Preparing Data<br />
	$query2 = sprintf(&#8220;select * from %s&#8221;,$tableName);<br />
	$datas = $base-&gt;query($query2);<br />
	$inserts = array();<br />
	while($data = $datas-&gt;fetchArray())<br />
	{<br />
		$insert = sprintf(&#8220;insert into %s (&#8220;,$tableName);<br />
		foreach ($cols as$col)<br />
			$insert .= &#8220;&#8216;&#8221;.$col.&#8221;&#8216;,&#8221;;<br />
		$insert = rtrim($insert,&#8217;,');<br />
		$insert .= &#8220;) values (&#8220;;<br />
		foreach($cols as $col)<br />
			$insert .= &#8220;&#8216;&#8221;.$data[$col].&#8221;&#8216;,&#8221;;<br />
		$insert = rtrim($insert,&#8217;,');<br />
			$insert .= &#8220;)&#8221;;<br />
		array_push($inserts,$insert);<br />
	} </p>
<p>	$sqlDrop = sprintf(&#8220;drop table %s&#8221;,$tableName);<br />
	$base-&gt;exec($sqlDrop);<br />
	$base-&gt;exec($sqlCreate);<br />
	foreach($inserts as $insert)<br />
		$base-&gt;exec($insert);<br />
	$base-&gt;close();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tung</title>
		<link>http://www.taiwangeek.com/2010-08/phppdosqlite-drop-columns-function.html/comment-page-1#comment-81</link>
		<dc:creator>tung</dc:creator>
		<pubDate>Sat, 06 Nov 2010 03:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.taiwangeek.com/?p=1317#comment-81</guid>
		<description>Great! I&#039;m happy that code help~</description>
		<content:encoded><![CDATA[<p>Great! I&#8217;m happy that code help~</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David-J. CHEMLA</title>
		<link>http://www.taiwangeek.com/2010-08/phppdosqlite-drop-columns-function.html/comment-page-1#comment-80</link>
		<dc:creator>David-J. CHEMLA</dc:creator>
		<pubDate>Fri, 05 Nov 2010 12:27:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.taiwangeek.com/?p=1317#comment-80</guid>
		<description>Hello from France,
I support Taiwan against Chinese dictators !
Thanks for this code, very helpful !
I use it for an application generator in PHP / Sqlite I am developping.</description>
		<content:encoded><![CDATA[<p>Hello from France,<br />
I support Taiwan against Chinese dictators !<br />
Thanks for this code, very helpful !<br />
I use it for an application generator in PHP / Sqlite I am developping.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (request URI doesn't have a trailing slash)

Served from: www.taiwangeek.com @ 2012-05-19 05:43:27 -->
