<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: INSERT code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 02:11:37 GMT</pubDate>
    <description>DZone Snippets: INSERT code</description>
    <item>
      <title>MSSQL 2005 - Add ID value to ID column when INSERTING </title>
      <link>http://snippets.dzone.com/posts/show/4521</link>
      <description>// @TableName is obviously the TABLE name u use&lt;br /&gt;// @ColumnName is obviously the COLUMN name u use&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;---Get next ID number&lt;br /&gt;	DECLARE &lt;br /&gt;		@ID int&lt;br /&gt;	&lt;br /&gt;	IF (SELECT count(*) FROM @TableName ) &gt; 0&lt;br /&gt;		BEGIN&lt;br /&gt;			SELECT @ID  = max(ColumnName ) from @TableName&lt;br /&gt;			SET @ID = @ID + 1 &lt;br /&gt;		END&lt;br /&gt;	ELSE&lt;br /&gt;	BEGIN&lt;br /&gt;		SET @ID  = 1&lt;br /&gt;	END&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Sep 2007 07:50:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4521</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>PHP: Insert Data Into MySQL Table Using An Array</title>
      <link>http://snippets.dzone.com/posts/show/4350</link>
      <description>Inserts the values of an array into a table. Also supports specifying if a specific field needs to be encoded using PASSWORD()&lt;br /&gt;Parameters:&lt;br /&gt;Table: Name of table to insert into&lt;br /&gt;Data: array of $field-&gt;$value of new data&lt;br /&gt;Password Field: Which field in the data array needs to be surrounded with PASSWORD() (optional)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function mysql_insert_array($table, $data, $password_field = "") {&lt;br /&gt;	foreach ($data as $field=&gt;$value) {&lt;br /&gt;		$fields[] = '`' . $field . '`';&lt;br /&gt;		&lt;br /&gt;		if ($field == $password_field) {&lt;br /&gt;			$values[] = "PASSWORD('" . mysql_real_escape_string($value) . "')";&lt;br /&gt;		} else {&lt;br /&gt;			$values[] = "'" . mysql_real_escape_string($value) . "'";&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	$field_list = join(',', $fields);&lt;br /&gt;	$value_list = join(', ', $values);&lt;br /&gt;	&lt;br /&gt;	$query = "INSERT INTO `" . $table . "` (" . $field_list . ") VALUES (" . $value_list . ")";&lt;br /&gt;	&lt;br /&gt;	return $query;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jul 2007 22:59:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4350</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>C#: Break Long Strings of Text That Don't Contain A Space</title>
      <link>http://snippets.dzone.com/posts/show/4335</link>
      <description>Long strings of text with no spaces breaks most tables since the browser doesn't know where to start a new line. This function breaks a string after a number of characters so that they can be properly displayed in tables&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// Put this at the top&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;//&lt;br /&gt;&lt;br /&gt;public string BreakLongString(string SubjectString, int CharsToBreakAfter)&lt;br /&gt;{&lt;br /&gt;	string Pattern = "\\S{" + CharsToBreakAfter + ",}";&lt;br /&gt;	int Counter = 0;&lt;br /&gt;	bool IsMatching = Regex.IsMatch(SubjectString, Pattern);&lt;br /&gt;	while (IsMatching)&lt;br /&gt;	{&lt;br /&gt;&lt;br /&gt;		Counter++;&lt;br /&gt;		string MatchedString = Regex.Match(SubjectString, Pattern).Value;&lt;br /&gt;		SubjectString = SubjectString.Replace(MatchedString.Substring(0, (CharsToBreakAfter - 1)), MatchedString.Substring(0, (CharsToBreakAfter - 1)) + " ");&lt;br /&gt;&lt;br /&gt;		// Prevent endless loops&lt;br /&gt;		if (Counter &gt; 20) break;&lt;br /&gt;&lt;br /&gt;		// Check if we still have long strings&lt;br /&gt;		IsMatching = Regex.IsMatch(SubjectString, Pattern);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	return SubjectString;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 22:51:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4335</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>Get last MySQL AUTO_INCREMENT ID</title>
      <link>http://snippets.dzone.com/posts/show/1657</link>
      <description>// Get last MySQL AUTO_INCREMENT ID&lt;br /&gt;// http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;SELECT LAST_INSERT_ID();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 08 Mar 2006 13:42:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1657</guid>
      <author>iansealy (Ian Sealy)</author>
    </item>
  </channel>
</rss>
