Skip to content

Commit

Permalink
mssql 2000
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 16, 2013
1 parent ad435c8 commit 243423c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 165 deletions.
Expand Up @@ -125,7 +125,7 @@ protected boolean supportsDisableTriggers() {
if (supportsDisableTriggers == null) {
try {
getPlatform().getSqlTemplate().update("set context_info 0x0");
log.warn("This database DOES support disabling triggers during a symmetricds data load");
log.info("This database DOES support disabling triggers during a symmetricds data load");
supportsDisableTriggers = true;
} catch (Exception ex) {
log.warn("This database does NOT support disabling triggers during a symmetricds data load");
Expand Down
@@ -1,160 +1,90 @@
package org.jumpmind.symmetric.db.mssql2000;

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.db.mssql.MsSqlSymmetricDialect;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.service.IParameterService;

public class MsSql2000SymmetricDialect extends MsSqlSymmetricDialect {


public MsSql2000SymmetricDialect(IParameterService parameterService, IDatabasePlatform platform) {
// Grandparent code called here because we can't call parent constructor.
this.parameterService = parameterService;
this.platform = platform;

log.info("The DbDialect being used is {}", this.getClass().getName());

buildSqlReplacementTokens();

ISqlTemplate sqlTemplate = this.platform.getSqlTemplate();
this.databaseMajorVersion = sqlTemplate.getDatabaseMajorVersion();
this.databaseMinorVersion = sqlTemplate.getDatabaseMinorVersion();
this.databaseName = sqlTemplate.getDatabaseProductName();
this.databaseProductVersion = sqlTemplate.getDatabaseProductVersion();
this.driverName = sqlTemplate.getDriverName();
this.driverVersion = sqlTemplate.getDriverVersion();


// Parent code
super(parameterService, platform);
this.triggerTemplate = new MsSql2000TriggerTemplate(this);
}

@Override
public String getTransactionTriggerExpression(String defaultCatalog, String defaultSchema,
Trigger trigger) {


// String text = "if (@@TRANCOUNT > 0) " +
// " begin\r\n" +
// " execute sp_getbindtoken @TransactionId output;\r\n" +
// " end";


// Change TransactionId to TransactionIdExp to avoid duplicate var names.
// String text = "declare @TransactionIdExp varchar;\r\n" +
// "if (@@TRANCOUNT > 0) begin\r\n" +
// " execute sp_getbindtoken @TransactionIdExp output;\r\n" +
// "end\r\n" +
// "select @TransactionIdExp";
return "@TransactionId";
// return text;
}



@Override
protected void createRequiredDatabaseObjects() {
// TODO: change name from base64 to hex
String encode = this.parameterService.getTablePrefix() + "_" + "base64_encode";
if (!installed(SQL_FUNCTION_INSTALLED, encode)) {
String sql = " create function dbo.$(functionName) (\r\n" +
" @binvalue varbinary(255)) returns varchar(2000)\r\n" +
" as \r\n" +
" begin\r\n" +
" declare @charvalue varchar(255)\r\n" +
" declare @i int\r\n" +
" declare @length int\r\n" +
" declare @hexstring char(16)\r\n" +
"\r\n" +
" select @charvalue = ''\r\n" +
" select @i = 1\r\n" +
" select @length = datalength(@binvalue)\r\n" +
" select @hexstring = '0123456789abcdef'\r\n" +
"\r\n" +
" while (@i <= @length)\r\n" +
" begin\r\n" +
"\r\n" +
" declare @tempint int\r\n" +
" declare @firstint int\r\n" +
" declare @secondint int\r\n" +
"\r\n" +
" select @tempint = convert(int, substring(@binvalue,@i,1))\r\n" +
" select @firstint = floor(@tempint/16)\r\n" +
" select @secondint = @tempint - (@firstint*16)\r\n" +
"\r\n" +
" select @charvalue = @charvalue +\r\n" +
" substring(@hexstring, @firstint+1, 1) +\r\n" +
" substring(@hexstring, @secondint+1, 1)\r\n" +
"\r\n" +
" select @i = @i + 1\r\n" +
" end\r\n" +
" return @charvalue\r\n" +
String sql = " create function dbo.$(functionName) (\n" +
" @binvalue varbinary(8000)) returns varchar(8000)\n" +
" as \n" +
" begin\n" +
" declare @charvalue varchar(8000)\n" +
" declare @i int\n" +
" declare @length int\n" +
" declare @hexstring char(16)\n" +
"\n" +
" select @charvalue = ''\n" +
" select @i = 1\n" +
" select @length = datalength(@binvalue)\n" +
" select @hexstring = '0123456789abcdef'\n" +
"\n" +
" while (@i <= @length)\n" +
" begin\n" +
"\n" +
" declare @tempint int\n" +
" declare @firstint int\n" +
" declare @secondint int\n" +
"\n" +
" select @tempint = convert(int, substring(@binvalue,@i,1))\n" +
" select @firstint = floor(@tempint/16)\n" +
" select @secondint = @tempint - (@firstint*16)\n" +
"\n" +
" select @charvalue = @charvalue +\n" +
" substring(@hexstring, @firstint+1, 1) +\n" +
" substring(@hexstring, @secondint+1, 1)\n" +
"\n" +
" select @i = @i + 1\n" +
" end\n" +
" return @charvalue\n" +
" end";
install(sql, encode);
}

// SELECT @Context_Info = CONTEXT_INFO
// FROM master.dbo.SYSPROCESSES
// WHERE SPID = @@SPID
String triggersDisabled = this.parameterService.getTablePrefix() + "_" + "triggers_disabled";
if (!installed(SQL_FUNCTION_INSTALLED, triggersDisabled)) {
String sql =
"create function dbo.$(functionName)() returns smallint \r\n" +
" begin \r\n" +
" declare @disabled varchar(1);\r\n" +
" declare @context_info varchar; \r\n" +
" SELECT @Context_Info = CONTEXT_INFO\r\n" +
" FROM master.dbo.SYSPROCESSES \r\n" +
" WHERE SPID = @@SPID \r\n" +
" set @disabled = coalesce(replace(substring(cast(@context_info as varchar), 1, 1), 0x0, ''), ''); \r\n" +
" if @disabled is null or @disabled != '1' \r\n" +
" return 0; \r\n" +
" return 1; \r\n" +
"create function dbo.$(functionName)() returns smallint \n" +
" begin \n" +
" declare @disabled varchar(1);\n" +
" declare @context_info varbinary(128); \n" +
" SELECT @Context_Info = CONTEXT_INFO\n" +
" FROM master.dbo.SYSPROCESSES \n" +
" WHERE SPID = @@SPID \n" +
" set @disabled = coalesce(replace(substring(cast(@context_info as varchar), 1, 1), 0x0, ''), ''); \n" +
" if @disabled is null or @disabled != '1' \n" +
" return 0; \n" +
" return 1; \n" +
" end ";
install(sql, triggersDisabled);
}
// String triggersDisabled = this.parameterService.getTablePrefix() + "_" + "triggers_disabled";
// if (!installed(SQL_FUNCTION_INSTALLED, triggersDisabled)) {
// String sql = "create function dbo.$(functionName)() returns smallint " +
// " begin " +
// " declare @disabled varchar(1); " +
// " set @disabled = coalesce(replace(substring(cast(context_info() as varchar), 1, 1), 0x0, ''), ''); " +
// " if @disabled is null or @disabled != '1' " +
// " return 0; " +
// " return 1; " +
// " end ";
// install(sql, triggersDisabled);
// }




String nodeDisabled = this.parameterService.getTablePrefix() + "_" + "node_disabled";
if (!installed(SQL_FUNCTION_INSTALLED, nodeDisabled)) {
String sql = "create function dbo.$(functionName)() returns varchar(50) " +
" begin " +
" declare @node varchar(50); " +
" declare @context_info varchar; \r\n" +
" SELECT @Context_Info = CONTEXT_INFO\r\n" +
" FROM master.dbo.SYSPROCESSES \r\n" +
" WHERE SPID = @@SPID " +
" set @node = coalesce(replace(substring(cast(@context_info as varchar) collate SQL_Latin1_General_CP1_CI_AS, 2, 50), 0x0, ''), ''); " +
String sql = "create function dbo.$(functionName)() returns varchar(50) \n" +
" begin \n" +
" declare @node varchar(50);\n" +
" declare @context_info varbinary(128);\n" +
" SELECT @context_info = CONTEXT_INFO\n" +
" FROM master.dbo.SYSPROCESSES \n" +
" WHERE SPID = @@SPID \n " +
" SELECT @node = coalesce(replace(substring(cast(@context_info as varchar) collate SQL_Latin1_General_CP1_CI_AS, 2, 50), 0x0, ''), ''); \n " +
" return @node; " +
" end ";
install(sql, nodeDisabled);
}
// String nodeDisabled = this.parameterService.getTablePrefix() + "_" + "node_disabled";
// if (!installed(SQL_FUNCTION_INSTALLED, nodeDisabled)) {
// String sql = "create function dbo.$(functionName)() returns varchar(50) " +
// " begin " +
// " declare @node varchar(50); " +
// " set @node = coalesce(replace(substring(cast(context_info() as varchar) collate SQL_Latin1_General_CP1_CI_AS, 2, 50), 0x0, ''), ''); " +
// " return @node; " +
// " end ";
// install(sql, nodeDisabled);
// }

}

Expand Down

0 comments on commit 243423c

Please sign in to comment.