登录

用户名:

密码:
MSSQLCreateUUID([format])     
作者:nsr131421
发部日期:Tue, 04/17/2007

判断字符串类型根据类型自动生成随机数
/**
 * Creates UUIDs safe for use in MSSQL UNIQUEIDENTIFIER fields.
 *
 * @param format   UUID format to generate.  Options are String or Binary. (Optional)
 * @return Returns a string.
 * @author Chip Temm (chip@anthrologik.net)
 * @version 1, June 27, 2002
 */
function MSSQL_createUUID(){
 var format = 'string';
 // uniqueidentifier wombat_createUUID([string FORMAT])
 //returns a UUID in the format specified. 
 //optional argument FORMAT defaults to string (MS-SQL uniqueidentifier safe)
 //accepts 'binary' or 'string'.  other values fail quietly to 'string'
 
 
 if(arraylen(Arguments)){
  if(arguments[1] eq 'binary' or arguments[1] eq 'string'){
   format = arguments[1];
  }
 }
 
 if(format eq 'string'){
  return Insert("-", CREATEuuid(), 23);
  /***   NOTE quoted usage is SQL statement:
  Insert into attribute (attributeID) values ('#wombat_createUUID()#')
  ***/
 
 }else{//must be raw binary
  return '0x' & Replace(CREATEuuid(),'-','','All');
  /***   NOTE UN-quoted usage is SQL statement:
  Insert into attribute (attributeID) values (#wombat_createUUID('binary')#)
  Good for cases where the value maybe either NULL or a UUID
  (neither of which should be quoted)
  ***/
 }
}


cfquery ....

Insert into myTable

(myTableID, name)

VALUES

(#MSSQL_createUUID('binary')#,'Joe Bloggs')

/cfquery



cfquery ....

Insert into myTable

(myTableID, name)

VALUES

('#MSSQL_createUUID('string')#','Joe Bloggs')

/cfquery


cfquery ....

Insert into myTable

(myTableID, name)

VALUES

('#MSSQL_createUUID()#','Joe Bloggs')

/cfquery

最后更新:Tue, 04/17/2007