Friday, 18 April 2008

How to use IF statment in MySQL

--
-- Definition of procedure `sp_location_select`
--

DROP PROCEDURE IF EXISTS `sp_location_select`;

DELIMITER $$

/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_location_select`(

in _ID bigint,
in _Name varchar(50),
in _Description varchar(50)

)
BEGIN

IF (_ID is not null) THEN
Select * From location WHERE ID = _ID;
ELSE
SELECT * From location;
END IF;

END $$
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */ $$

DELIMITER ;

How to create a procedure in MySQL

--
-- Definition of procedure `sp_eventuser_insert`
--

DROP PROCEDURE IF EXISTS `sp_eventuser_insert`;

DELIMITER $$

/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_eventuser_insert`(
in _UID bigint,
in _EID bigint,
in _Name varchar(100),
in _Description varchar(300)
)
BEGIN

Insert into eventuser
(
Name ,
Description,
UID ,
EID,
GUID,
InsertTimeStamp
) values(
_Name ,
_Description,
_UID ,
_EID,
UUID(),
NOW()
);

SELECT @@IDENTITY;

END $$
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */ $$

DELIMITER ;

How to create a table in MySQL

DROP TABLE IF EXISTS `album`;
CREATE TABLE `album` (
`ID` bigint(20) NOT NULL auto_increment,
`PID` bigint(20) NOT NULL,
`GUID` varchar(36) default 'UUID()',
`InsertTimeStamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
`UpdateTimeStamp` datetime NOT NULL,
`DeleteTimeStamp` datetime NOT NULL,
`Description` varchar(100) NOT NULL,
`Name` varchar(100) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Monday, 14 April 2008

How to download a stream into a document?

How to download a stream into a document.

Response.Clear();
Response.ContentType = "binary/octet-stream";//application
Response.AddHeader("Content-Disposition", "attachment; filename=Myfile.pdf ; size=" + b.Length.ToString());
Response.AddHeader("Content-Length", b.Length.ToString());
Response.BinaryWrite(b);
Response.End();

You might notice sometimes that the download attaches the text of the aspx page that you are using to download the document some times. This problem is caused by not setting the Length in the context line.