public static string SelectUsedMessages(DBLangEngine.DatabaseType dbType, string culture) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return("SELECT MESSAGENAME, VALUE, COMMENT_EN_US, CULTURE, IFNULL(INUSE, 0) AS INUSE " + "FROM MESSAGES " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY MESSAGENAME, VALUE "); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return("SELECT MESSAGENAME, VALUE, COMMENT_EN_US, CULTURE, IFNULL(INUSE, 0) AS INUSE " + "FROM MESSAGES " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY MESSAGENAME, VALUE "); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return("SELECT MESSAGENAME, VALUE, COMMENT_EN_US, CULTURE, COALESCE(INUSE, 0) AS INUSE " + "FROM " + schema + "MESSAGES " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY MESSAGENAME, VALUE "); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return("SELECT MESSAGENAME, VALUE, COMMENT_EN_US, CULTURE, ISNULL(INUSE, 0) AS INUSE " + "FROM " + schema + "MESSAGES " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY MESSAGENAME, VALUE "); } else { throw new NotImplementedException(); } }
public static string SelectDumpFormItems(DBLangEngine.DatabaseType dbType) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return ("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE " + "FROM FORMITEMS " + "ORDER BY CULTURE, APP_FORM, ITEM, PROPERTYNAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return ("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE " + "FROM FORMITEMS " + "ORDER BY CULTURE, APP_FORM, ITEM, PROPERTYNAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return ("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE " + "FROM " + schema + "FORMITEMS " + "ORDER BY CULTURE, APP_FORM, ITEM, PROPERTYNAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return ("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE " + "FROM " + schema + "FORMITEMS " + "ORDER BY CULTURE, APP_FORM, ITEM, PROPERTYNAME, VALUE; "); } else { throw new NotImplementedException(); } }
public static string SelectUsedCultures(DBLangEngine.DatabaseType dbType, string culture) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, IFNULL(INUSE, 0) AS INUSE " + "FROM FORMITEMS " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY APP_FORM, ITEM"); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, IFNULL(INUSE, 0) AS INUSE " + "FROM FORMITEMS " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY APP_FORM, ITEM"); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, COALESCE(INUSE, 0) AS INUSE " + "FROM " + schema + "FORMITEMS " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY APP_FORM, ITEM"); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return("SELECT APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, ISNULL(INUSE, 0) AS INUSE " + "FROM " + schema + "FORMITEMS " + "WHERE CULTURE = " + DBUtils.MkStr(culture) + " " + "ORDER BY APP_FORM, ITEM"); } else { throw new NotImplementedException(); } }
public static string SelectDumpMessages(DBLangEngine.DatabaseType dbType) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return ("SELECT CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE " + "FROM MESSAGES " + "ORDER BY CULTURE, MESSAGENAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return ("SELECT CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE " + "FROM MESSAGES " + "ORDER BY CULTURE, MESSAGENAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return ("SELECT CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE " + "FROM " + schema + "MESSAGES " + "ORDER BY CULTURE, MESSAGENAME, VALUE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return ("SELECT CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE " + "FROM " + schema + "MESSAGES " + "ORDER BY CULTURE, MESSAGENAME, VALUE; "); } else { throw new NotImplementedException(); } }
public static string DeleteUnusedFormItems(DBLangEngine.DatabaseType dbType, string culture) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return (string.Format("DELETE FROM FORMITEMS WHERE IFNULL(INUSE, 0) = 0 AND CULTURE = {0}; ", DBUtils.MkStr(culture))); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return (string.Format("DELETE FROM FORMITEMS WHERE IFNULL(INUSE, 0) = 0 AND CULTURE = {0}; ", DBUtils.MkStr(culture))); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return (string.Format("DELETE FROM " + schema + "FORMITEMS WHERE COALESCE(INUSE, 0) = 0 AND CULTURE = {0}; ", DBUtils.MkStr(culture))); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return (string.Format("DELETE FROM " + schema + "FORMITEMS WHERE ISNULL(INUSE, 0) = 0 AND CULTURE = {0}; ", DBUtils.MkStr(culture))); } else { throw new NotImplementedException(); } }
private void UpdateConnectionString() { KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)cmbDatabaseType.SelectedItem; DBLangEngine.DatabaseType dbType = v.Key; string connStr; switch (v.Key) { case DBLangEngine.DatabaseType.dtSQLite: connStr = cbOverrideConnectionString.Checked ? tbConnectionString.Text : "Data Source=" + tbServer.Text + ";Pooling=true;FailIfMissing=false"; break; case DBLangEngine.DatabaseType.dtMySQL: connStr = cbOverrideConnectionString.Checked ? tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};CharSet=utf8;", tbServer.Text, nudPort.Value, tbDatabase.Text, tbUser.Text, tbPassword.Text); break; case DBLangEngine.DatabaseType.dtPostgreSQL: connStr = cbOverrideConnectionString.Checked ? tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", tbServer.Text, nudPort.Value, tbDatabase.Text, tbUser.Text, tbPassword.Text); break; case DBLangEngine.DatabaseType.dtMSSQL: connStr = cbOverrideConnectionString.Checked ? tbConnectionString.Text : string.Format("Persist Security Info=False;User ID={3};Password={4};Initial Catalog={2};Server={0};", tbServer.Text, nudPort.Value, tbDatabase.Text, tbUser.Text, tbPassword.Text); break; default: connStr = string.Empty; break; } if (!cbOverrideConnectionString.Checked) { tbConnectionString.Text = connStr; } }
public static string UpdateFormItems(DBLangEngine.DatabaseType dbType, object value, object culture, object app, object form, object propertyName, object item) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return (string.Format("UPDATE FORMITEMS SET VALUE = {0} " + "WHERE CULTURE = {1} AND APP_FORM = {2} AND PROPERTYNAME = {3} AND ITEM = {4}; ", DBUtils.MkStr(value.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(item.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return (string.Format("UPDATE FORMITEMS SET VALUE = {0} " + "WHERE CULTURE = {1} AND APP_FORM = {2} AND PROPERTYNAME = {3} AND ITEM = {4}; ", DBUtils.MkStr(value.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(item.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return (string.Format("UPDATE " + schema + "FORMITEMS SET VALUE = {0} " + "WHERE CULTURE = {1} AND APP_FORM = {2} AND PROPERTYNAME = {3} AND ITEM = {4}; ", DBUtils.MkStr(value.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(item.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return (string.Format("UPDATE " + schema + "FORMITEMS SET VALUE = {0} " + "WHERE CULTURE = {1} AND APP_FORM = {2} AND PROPERTYNAME = {3} AND ITEM = {4}; ", DBUtils.MkStr(value.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(item.ToString()))); } else { throw new NotImplementedException(); } }
public static void SetSchema(DBLangEngine.DatabaseType dbType, string schemaName) { if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { schema = schemaName == string.Empty ? string.Empty : "[" + schemaName + "]."; } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { schema = schemaName == string.Empty ? string.Empty : schemaName + "."; } else { schema = string.Empty; } }
public static bool Execute(out DBLangEngine.DatabaseType dbType) { FormSelectDBType frm = new FormSelectDBType(); if (frm.ShowDialog() == DialogResult.OK) { KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)frm.cmbDatabaseType.SelectedItem; dbType = v.Key; return(true); } else { dbType = DBLangEngine.DatabaseType.dtSQLite; return(false); } }
private void OpenDatabase(string fileName) { try { CloseDBConnection(); connStr = "Data Source=" + fileName + ";Pooling=true;FailIfMissing=false"; connSQLite = new SQLiteConnection(connStr); connSQLite.Open(); culture = new Culture(ref connSQLite); currentFile = fileName; captionStr = fileName; dbType = DBLangEngine.DatabaseType.dtSQLite; schema = string.Empty; } catch (Exception ex) { MessageBox.Show("Unable to connect to database ('" + ex.Message + "').", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SQLs.SetSchema(DBLangEngine.DatabaseType.dtSQLite, schema); Text = "DBLangVersion [" + captionStr + "]"; mnuSave.Enabled = true; mnuAddFromCulture.Enabled = true; mnuRemoveUnused.Enabled = true; cmbCulture.Enabled = true; mnuExportDatabase.Enabled = dbType == DBLangEngine.DatabaseType.dtSQLite; mnuAddFomEN_US.Enabled = false; mnuSelectCurrentCulture.Enabled = true; mnuDumpData.Enabled = true; cmbCulture.Items.AddRange(culture.Cultures.ToArray()); for (int i = 0; i < cmbCulture.Items.Count; i++) { if ((cmbCulture.Items[i] as Culture).LCID == 1033) { cmbCulture.SelectedIndex = i; } cmbCulture.AutoCompleteCustomSource.Add((cmbCulture.Items[i] as Culture).NativeName); } mnuSelectSomeCulture.Enabled = true; ListCulturesMenu(); }
public static bool Execute(out DBLangEngine.DatabaseType dbType, out string connStr, out string captionStr, out string schema) { FormLoginDatabase frm = new FormLoginDatabase(); schema = string.Empty; if (frm.ShowDialog() == DialogResult.OK) { KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)frm.cmbDatabaseType.SelectedItem; dbType = v.Key; switch (v.Key) { case DBLangEngine.DatabaseType.dtSQLite: connStr = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : "Data Source=" + frm.tbServer.Text + ";Pooling=true;FailIfMissing=false"; captionStr = frm.tbServer.Text; break; case DBLangEngine.DatabaseType.dtMySQL: connStr = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};CharSet=utf8;", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text); captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text; break; case DBLangEngine.DatabaseType.dtPostgreSQL: connStr = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text); captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text; schema = frm.tbSchema.Text; break; case DBLangEngine.DatabaseType.dtMSSQL: connStr = frm.cbOverrideConnectionString.Checked ? frm.tbConnectionString.Text : string.Format("Persist Security Info=False;User ID={3};Password={4};Initial Catalog={2};Server={0};", frm.tbServer.Text, frm.nudPort.Value, frm.tbDatabase.Text, frm.tbUser.Text, frm.tbPassword.Text); captionStr = frm.tbServer.Text + ":" + frm.tbDatabase.Text; schema = frm.tbSchema.Text; break; default: connStr = string.Empty; captionStr = "DBLangVersion"; break; } return(true); } connStr = string.Empty; dbType = DBLangEngine.DatabaseType.dtSQLite; captionStr = "DBLangVersion"; return(false); }
public static string UpdateMessage(DBLangEngine.DatabaseType dbType, object message, object messageCulture, object messageName) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return (string.Format("UPDATE MESSAGES SET VALUE = {0} " + "WHERE CULTURE = {1} AND MESSAGENAME = {2}; ", DBUtils.MkStr(message.ToString()), DBUtils.MkStr(messageCulture.ToString()), DBUtils.MkStr(messageName.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return (string.Format("UPDATE MESSAGES SET VALUE = {0} " + "WHERE CULTURE = {1} AND MESSAGENAME = {2}; ", DBUtils.MkStr(message.ToString()), DBUtils.MkStr(messageCulture.ToString()), DBUtils.MkStr(messageName.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return (string.Format("UPDATE " + schema + "MESSAGES SET VALUE = {0} " + "WHERE CULTURE = {1} AND MESSAGENAME = {2}; ", DBUtils.MkStr(message.ToString()), DBUtils.MkStr(messageCulture.ToString()), DBUtils.MkStr(messageName.ToString()))); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return (string.Format("UPDATE " + schema + "MESSAGES SET VALUE = {0} " + "WHERE CULTURE = {1} AND MESSAGENAME = {2}; ", DBUtils.MkStr(message.ToString()), DBUtils.MkStr(messageCulture.ToString()), DBUtils.MkStr(messageName.ToString()))); } else { throw new NotImplementedException(); } }
public static string SelectDistinctCulture(DBLangEngine.DatabaseType dbType) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return("SELECT DISTINCT CULTURE FROM FORMITEMS ORDER BY CULTURE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return("SELECT DISTINCT CULTURE FROM FORMITEMS ORDER BY CULTURE; "); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return("SELECT DISTINCT CULTURE FROM " + schema + "FORMITEMS ORDER BY CULTURE; "); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return("SELECT DISTINCT CULTURE FROM " + schema + "FORMITEMS ORDER BY CULTURE; "); } else { throw new NotImplementedException(); } }
private void LoadSettings() { Conflib cl = new Conflib(); cl.AutoCreateSettings = true; cl.DataDir = Path.GetDirectoryName(tbSaveConfigTo.Text); cl.DBName = Path.GetFileName(tbSaveConfigTo.Text); DBLangEngine.DatabaseType dbType = DBLangEngine.DatabaseType.dtSQLite; try { KeyValuePair <DBLangEngine.DatabaseType, string> v = new KeyValuePair <DBLangEngine.DatabaseType, string>((DBLangEngine.DatabaseType)Enum.Parse(typeof(DBLangEngine.DatabaseType), cl["dbType"]), GetEnumDescription((DBLangEngine.DatabaseType)Enum.Parse(typeof(DBLangEngine.DatabaseType), cl["dbType"]))); for (int i = 0; i < cmbDatabaseType.Items.Count; i++) { KeyValuePair <DBLangEngine.DatabaseType, string> item = (KeyValuePair <DBLangEngine.DatabaseType, string>)cmbDatabaseType.Items[i]; if (item.Equals(v)) { dbType = v.Key; cmbDatabaseType.SelectedIndex = i; break; } } } catch { cmbDatabaseType.SelectedIndex = 0; cmbDatabaseType_SelectedIndexChanged(null, null); } string dbServer = cl["dbServer", dbType == DBLangEngine.DatabaseType.dtSQLite ? GetDefaultFileLang() : "localhost"]; dbServer = dbServer == null ? dbType == DBLangEngine.DatabaseType.dtSQLite ? GetDefaultFileLang() : "localhost" : dbServer; // down we just like this ? format tbServer.Text = dbServer; tbDatabase.Text = cl["dbDatabase"]; tbUser.Text = cl["dbUser"]; tbPassword.Text = cl["dbPassword"]; tbSchema.Text = cl["dbSchema"]; try { cbNoTables.Checked = bool.Parse(cl["dbNoTables"]); } catch { cbNoTables.Checked = false; } try { nudPort.Value = decimal.Parse(cl["dbPort"]); } catch { nudPort.Value = 0; } string pwText = new string('•', tbPassword.Text.Length); try { tbConnectionString.Text = cl["dbConnStr"].Replace(cl["dbPassword"], pwText); } catch { // Do nothing } ReplacePasswordToReal(); try { cbOverrideConnectionString.Checked = bool.Parse(cl["dbConnStrOverride"]); } catch { cbOverrideConnectionString.Checked = false; } }
private void UpdateFormByDatabase(DBLangEngine.DatabaseType dbType) { lbServer.Text = "Server:"; btBrowse.Visible = false; tbConnectionString.ReadOnly = true; tbServer.Size = new Size(341, 20); tbServer.Enabled = true; tbDatabase.Enabled = true; tbUser.Enabled = true; tbPassword.Enabled = true; nudPort.Enabled = true; tbSchema.Enabled = true; cbUsePort.Checked = true; cbUsePort.Enabled = false; lbServer.Enabled = true; lbDatabase.Enabled = true; lbUser.Enabled = true; lbPassword.Enabled = true; lbPort.Enabled = true; lbSchema.Enabled = true; cbOverrideConnectionString.Checked = false; btBrowse.Visible = false; ClearFields(); switch (dbType) { case DBLangEngine.DatabaseType.dtSQLite: tbDatabase.Enabled = false; tbUser.Enabled = false; tbPassword.Enabled = false; nudPort.Enabled = false; tbSchema.Enabled = false; lbDatabase.Enabled = false; lbUser.Enabled = false; lbPassword.Enabled = false; lbPort.Enabled = false; lbSchema.Enabled = false; lbServer.Text = "File name:"; tbServer.Text = GetDefaultFileLang(); tbServer.Size = new Size(306, 20); btBrowse.Visible = true; break; case DBLangEngine.DatabaseType.dtMySQL: lbSchema.Enabled = false; tbSchema.Enabled = false; tbServer.Text = "localhost"; tbUser.Text = string.Empty; tbPassword.Text = string.Empty; nudPort.Value = 3306; break; case DBLangEngine.DatabaseType.dtMSSQL: cbUsePort.Checked = false; cbUsePort.Enabled = true; tbServer.Text = "localhost"; tbSchema.Text = "dbo"; nudPort.Value = 1433; break; case DBLangEngine.DatabaseType.dtPostgreSQL: tbServer.Text = "localhost"; tbSchema.Text = "public"; nudPort.Value = 5432; break; } BuildConnectionString(null, null); }
public static string InsertFormItems(DBLangEngine.DatabaseType dbType, object app, object form, object item, object culture, object propertyName, object valueType, object value, object inUse) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return (string.Format("INSERT INTO FORMITEMS (APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} " + "WHERE NOT EXISTS (SELECT 1 FROM FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}); " + "UPDATE FORMITEMS SET INUSE = {6} WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}; ", DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(item.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(valueType.ToString()), DBUtils.MkStr(value.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return (string.Format("INSERT INTO FORMITEMS (APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} FROM DUAL " + "WHERE NOT EXISTS (SELECT * FROM FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}) LIMIT 1; " + "UPDATE FORMITEMS SET INUSE = {6} WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}; ", DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(item.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(valueType.ToString()), DBUtils.MkStr(value.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return (string.Format("INSERT INTO " + schema + "FORMITEMS (APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} " + "WHERE NOT EXISTS (SELECT 1 FROM FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}); " + "UPDATE " + schema + "FORMITEMS SET INUSE = {6} WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}; ", DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(item.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(valueType.ToString()), DBUtils.MkStr(value.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return (string.Format("INSERT INTO " + schema + "FORMITEMS (APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} " + "WHERE NOT EXISTS (SELECT 1 FROM FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}); " + "UPDATE " + schema + "FORMITEMS SET INUSE = {6} WHERE APP_FORM = {0} AND ITEM = {1} AND " + "CULTURE = {2} AND PROPERTYNAME = {3}; ", DBUtils.MkStr(app.ToString() + "." + form.ToString()), DBUtils.MkStr(item.ToString()), DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(propertyName.ToString()), DBUtils.MkStr(valueType.ToString()), DBUtils.MkStr(value.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else { throw new NotImplementedException(); } }
public static string InsertMessages(DBLangEngine.DatabaseType dbType, object culture, object messageName, object value, object commentEN_US, object inUse) { if (dbType == DBLangEngine.DatabaseType.dtSQLite) { return (string.Format("INSERT INTO MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4} " + "WHERE NOT EXISTS(SELECT 1 FROM MESSAGES WHERE CULTURE = {0} AND MESSAGENAME = {1}); " + "UPDATE MESSAGES SET INUSE = {4} WHERE CULTURE = {0} AND MESSAGENAME = {1}; ", DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(messageName.ToString()), DBUtils.MkStr(value.ToString()), DBUtils.MkStr(commentEN_US.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtMySQL) { return (string.Format("INSERT INTO MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4} FROM DUAL " + "WHERE NOT EXISTS(SELECT * FROM MESSAGES WHERE CULTURE = {0} AND MESSAGENAME = {1}) LIMIT 1; " + "UPDATE MESSAGES SET INUSE = {4} WHERE CULTURE = {0} AND MESSAGENAME = {1}; ", DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(messageName.ToString()), DBUtils.MkStr(value.ToString()), DBUtils.MkStr(commentEN_US.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtPostgreSQL) { return (string.Format("INSERT INTO " + schema + "MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4} " + "WHERE NOT EXISTS(SELECT 1 FROM " + schema + "MESSAGES WHERE CULTURE = {0} AND MESSAGENAME = {1}); " + "UPDATE " + schema + "MESSAGES SET INUSE = {4} WHERE CULTURE = {0} AND MESSAGENAME = {1}; ", DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(messageName.ToString()), DBUtils.MkStr(value.ToString()), DBUtils.MkStr(commentEN_US.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else if (dbType == DBLangEngine.DatabaseType.dtMSSQL) { return (string.Format("INSERT INTO " + schema + "MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " + "SELECT {0}, {1}, {2}, {3}, {4} " + "WHERE NOT EXISTS(SELECT 1 FROM " + schema + "MESSAGES WHERE CULTURE = {0} AND MESSAGENAME = {1}); " + "UPDATE " + schema + "MESSAGES SET INUSE = {4} WHERE CULTURE = {0} AND MESSAGENAME = {1}; ", DBUtils.MkStr(culture.ToString()), DBUtils.MkStr(messageName.ToString()), DBUtils.MkStr(value.ToString()), DBUtils.MkStr(commentEN_US.ToString()), (inUse.ToString() == false.ToString() ? "0" : "1"))); } else { throw new NotImplementedException(); } }