/plugins/dbmigrate/adapters/MicrosoftSQLServer.cfc

http://raihan.googlecode.com/ · ColdFusion CFScript · 84 lines · 67 code · 17 blank · 0 comment · 0 complexity · 6f32e3280dd9d8d03bd6a426fa6c0557 MD5 · raw file

  1. <cfcomponent extends="Abstract">
  2. <cfset variables.sqlTypes = {}>
  3. <cfset variables.sqlTypes['primaryKey'] = "INT NOT NULL IDENTITY(1,1) PRIMARY KEY">
  4. <cfset variables.sqlTypes['binary'] = {name='IMAGE'}>
  5. <cfset variables.sqlTypes['boolean'] = {name='BIT'}>
  6. <cfset variables.sqlTypes['date'] = {name='DATETIME'}>
  7. <cfset variables.sqlTypes['datetime'] = {name='DATETIME'}>
  8. <cfset variables.sqlTypes['decimal'] = {name='DECIMAL'}>
  9. <cfset variables.sqlTypes['float'] = {name='FLOAT'}>
  10. <cfset variables.sqlTypes['integer'] = {name='INT'}>
  11. <cfset variables.sqlTypes['string'] = {name='VARCHAR',limit=255}>
  12. <cfset variables.sqlTypes['text'] = {name='TEXT'}>
  13. <cfset variables.sqlTypes['time'] = {name='DATETIME'}>
  14. <cfset variables.sqlTypes['timestamp'] = {name='DATETIME'}>
  15. <cffunction name="adapterName" returntype="string" access="public" hint="name of database adapter">
  16. <cfreturn "MicrosoftSQLServer">
  17. </cffunction>
  18. <!--- SQL Server uses square brackets to escape table and column names --->
  19. <cffunction name="quoteTableName" returntype="string" access="public" hint="surrounds table or index names with quotes">
  20. <cfargument name="name" type="string" required="true" hint="column name">
  21. <cfreturn "[#Replace(arguments.name,".","`.`","ALL")#]">
  22. </cffunction>
  23. <cffunction name="quoteColumnName" returntype="string" access="public" hint="surrounds column names with quotes">
  24. <cfargument name="name" type="string" required="true" hint="column name">
  25. <cfreturn "[#arguments.name#]">
  26. </cffunction>
  27. <!--- createTable - use default --->
  28. <cffunction name="renameTable" returntype="string" access="public" hint="generates sql to rename a table">
  29. <cfargument name="oldName" type="string" required="true" hint="old table name">
  30. <cfargument name="newName" type="string" required="true" hint="new table name">
  31. <cfreturn "EXEC sp_rename '#arguments.oldName#', '#arguments.newName#'">
  32. </cffunction>
  33. <cffunction name="dropTable" returntype="string" access="public" hint="generates sql to drop a table">
  34. <cfargument name="name" type="string" required="true" hint="table name">
  35. <cfreturn "IF EXISTS(SELECT name FROM sysobjects WHERE name = N'#LCase(arguments.name)#' AND xtype='U') DROP TABLE #quoteTableName(LCase(arguments.name))#">
  36. </cffunction>
  37. <cffunction name="addColumnToTable" returntype="string" access="public" hint="generates sql to add a new column to a table">
  38. <cfargument name="name" type="string" required="true" hint="table name">
  39. <cfargument name="column" type="any" required="true" hint="column definition object">
  40. <cfreturn "ALTER TABLE #quoteTableName(LCase(arguments.name))# ADD #arguments.column.toSQL()#">
  41. </cffunction>
  42. <cffunction name="changeColumnInTable" returntype="string" access="public" hint="generates sql to change an existing column in a table">
  43. <cfargument name="name" type="string" required="true" hint="table name">
  44. <cfargument name="column" type="any" required="true" hint="column definition object">
  45. <cfreturn "ALTER TABLE #quoteTableName(LCase(arguments.name))# ALTER COLUMN #arguments.column.toSQL()#">
  46. </cffunction>
  47. <cffunction name="renameColumnInTable" returntype="string" access="public" hint="generates sql to rename an existing column in a table">
  48. <cfargument name="name" type="string" required="true" hint="table name">
  49. <cfargument name="columnName" type="string" required="true" hint="old column name">
  50. <cfargument name="newColumnName" type="string" required="true" hint="new column name">
  51. <cfreturn "EXEC sp_rename '#LCase(arguments.name)#.#arguments.columnName#', '#arguments.newColumnName#'">
  52. </cffunction>
  53. <!--- dropColumnFromTable - use default --->
  54. <!--- addForeignKeyToTable - use default --->
  55. <cffunction name="dropForeignKeyFromTable" returntype="string" access="public" hint="generates sql to add a foreign key constraint to a table">
  56. <cfargument name="name" type="string" required="true" hint="table name">
  57. <cfargument name="keyName" type="any" required="true" hint="foreign key name">
  58. <cfreturn "ALTER TABLE #quoteTableName(LCase(arguments.name))# DROP CONSTRAINT #arguments.keyname#">
  59. </cffunction>
  60. <!--- foreignKeySQL - use default --->
  61. <!--- addIndex - use default --->
  62. <cffunction name="removeIndex" returntype="string" access="public" hint="generates sql to remove a database index">
  63. <cfargument name="table" type="string" required="true" hint="table name">
  64. <cfargument name="indexName" type="string" required="false" default="" hint="index name">
  65. <cfreturn "DROP INDEX #arguments.table#.#quoteColumnName(arguments.indexName)#">
  66. </cffunction>
  67. </cfcomponent>