public bool execCommandFile() { bool curReturn = true; int curDelimIdx; decimal curDatabaseVersion = 9999.00M; String inputBuffer, curSqlStmt = ""; StringBuilder curInputCmd = new StringBuilder( "" ); ImportData curImportData = new ImportData(); StreamReader myReader; myProgressInfo = new ProgressWindow(); #region Process all commands in the input file myReader = getImportFile(); if ( myReader != null ) { int curInputLineCount = 0; try { while ( ( inputBuffer = myReader.ReadLine() ) != null ) { curInputLineCount++; myProgressInfo.setProgressValue( curInputLineCount ); if ( inputBuffer.TrimStart( ' ' ).StartsWith( "## " ) ) { curDatabaseVersion = Convert.ToDecimal( inputBuffer.Substring( 4 ) ); } if ( inputBuffer.TrimStart( ' ' ).StartsWith( "//" ) || inputBuffer.TrimStart( ' ' ).StartsWith( "##" ) ) { } else { if ( curDatabaseVersion > myDatabaseVersion ) { curDelimIdx = inputBuffer.IndexOf( ';' ); if ( curDelimIdx >= 0 ) { if ( curDelimIdx > 0 ) { curInputCmd.Append( inputBuffer.Substring( 0, curDelimIdx ) ); } curSqlStmt = curInputCmd.ToString(); curSqlStmt.TrimStart( ' ' ); if ( curSqlStmt.Trim().ToUpper().StartsWith( "DROP " ) ) { execDropTable( replaceLinefeed( curSqlStmt ) ); } else if ( curSqlStmt.Trim().ToUpper().StartsWith( "CREATE " ) ) { execCreateTable( replaceLinefeed( curSqlStmt ) ); curInputCmd = new StringBuilder( "" ); } else { execSchemaCmd( replaceLinefeed( curSqlStmt ) ); } curInputCmd = new StringBuilder( "" ); } else { curInputCmd.Append( inputBuffer ); } } } } curSqlStmt = ""; System.Data.SqlServerCe.SqlCeEngine mySqlEngine = new SqlCeEngine(); mySqlEngine.LocalConnectionString = Properties.Settings.Default.waterskiConnectionStringApp; mySqlEngine.Shrink(); } catch ( Exception ex ) { curReturn = false; String ExcpMsg = ex.Message; if ( mySqlStmt != null ) { ExcpMsg += "\n" + curSqlStmt; } MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg ); } } #endregion myProgressInfo.Close(); return curReturn; }
private bool updateSchema(String inFileRef) { bool curReturnValue = true; int curDelimIdx; String inputBuffer, curSqlStmt = ""; StringBuilder curInputCmd = new StringBuilder( "" ); ImportData curImportData = new ImportData(); StreamReader myReader; myProgressInfo = new ProgressWindow(); try { #region Process all commands in the input file myReader = getImportFile( inFileRef ); if ( myReader != null ) { int curInputLineCount = 0; try { MessageBox.Show( "Your database is about to be upgraded. Please click OK or continue to any dialogs." ); while ( ( inputBuffer = myReader.ReadLine() ) != null ) { curInputLineCount++; myProgressInfo.setProgressValue( curInputLineCount ); if ( inputBuffer.TrimStart( ' ' ).StartsWith( "//" ) ) { } else { curDelimIdx = inputBuffer.IndexOf( ';' ); if ( curDelimIdx >= 0 ) { if ( curDelimIdx > 0 ) { curInputCmd.Append( inputBuffer.Substring( 0, curDelimIdx ) ); } curSqlStmt = curInputCmd.ToString(); curSqlStmt.TrimStart( ' ' ); if ( curSqlStmt.Trim().ToUpper().StartsWith( "DROP " ) ) { execDropTable( replaceLinefeed(curSqlStmt) ); } else if ( curSqlStmt.Trim().ToUpper().StartsWith( "CREATE " ) ) { execCreateTable( replaceLinefeed(curSqlStmt) ); curInputCmd = new StringBuilder( "" ); } else { execSchemaCmd( replaceLinefeed(curSqlStmt) ); } curInputCmd = new StringBuilder( "" ); } else { curInputCmd.Append( inputBuffer ); } } } curSqlStmt = ""; System.Data.SqlServerCe.SqlCeEngine mySqlEngine = new SqlCeEngine(); mySqlEngine.LocalConnectionString = Properties.Settings.Default.waterskiConnectionStringApp; mySqlEngine.Shrink(); } catch ( Exception ex ) { curReturnValue = false; String ExcpMsg = ex.Message; if ( mySqlStmt != null ) { ExcpMsg += "\n" + curSqlStmt; } MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg ); } } #endregion } catch ( Exception ex ) { curReturnValue = false; String ExcpMsg = ex.Message; if ( mySqlStmt != null ) { ExcpMsg += "\n" + mySqlStmt.CommandText; } MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg ); } myProgressInfo.Close(); return curReturnValue; }
private bool execCreateTable( String inSqlStmt ) { bool curReturnValue = true; int curDelimIdx, curDelimIdx2, curValueLen; ImportData curImportData = new ImportData(); String[] curTableName = new String[1]; try { curDelimIdx = inSqlStmt.ToUpper().IndexOf( "TABLE " ); if ( curDelimIdx > 0 ) { curDelimIdx2 = inSqlStmt.IndexOf( " ", curDelimIdx + 6 ); if ( curDelimIdx2 < 0 ) { curValueLen = inSqlStmt.Length - curDelimIdx - 6; } else { curValueLen = curDelimIdx2 - curDelimIdx - 6; } curTableName[0] = inSqlStmt.Substring( curDelimIdx + 6, curValueLen ); String curFileRef = Application.StartupPath + "\\" + curTableName[0] + ".tmp"; if ( execSchemaCmd( inSqlStmt ) ) { if ( !( curTableName[0].EndsWith( "Backup" ) ) ) { curImportData.importData( ( curFileRef ) ); deleteTempFile( curFileRef ); } } } } catch ( Exception ex ) { MessageBox.Show( "Error: Executing drop table command " + inSqlStmt + "\n\nException: " + ex.Message ); curReturnValue = false; } return curReturnValue; }
private bool loadTrickList() { bool curReturnValue = true; int rowsProc = 0; try { #region Insert current NOPS values mySqlStmt = myDbConn.CreateCommand(); mySqlStmt.CommandText = "Delete TrickList"; rowsProc = mySqlStmt.ExecuteNonQuery(); String curFileRef = Application.StartupPath + "\\TrickList.txt"; ImportData myImportData = new ImportData(); myImportData.importData( curFileRef ); #endregion } catch ( Exception ex ) { curReturnValue = false; String ExcpMsg = ex.Message; if ( mySqlStmt != null ) { ExcpMsg += "\n" + mySqlStmt.CommandText; } MessageBox.Show( "Error during addVerion optionation" + "\n\nError: " + ExcpMsg ); } return curReturnValue; }