Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. The type of the SQL statement could not be determinated
  2. <!-- language: sql -->
  3.  
  4.     CREATE TABLE STUDENT (
  5.     ID INTEGER NOT NULL PRIMARY KEY,
  6.     NAME VARCHAR(255) NOT NULL
  7.     );
  8.  
  9.     CREATE GENERATOR GEN_STUDENT_ID;
  10.  
  11.     SET TERM ^ ;
  12.     CREATE OR ALTER TRIGGER STUDENT_BI FOR STUDENT
  13.     ACTIVE BEFORE INSERT POSITION 0
  14.     AS
  15.     BEGIN
  16.        IF (NEW.ID IS NULL) THEN
  17.        NEW.ID = GEN_ID(GEN_STUDENT_ID,1);
  18.     END^
  19.  
  20.     SET TERM ; ^
  21.        
  22. FbConnectionStringBuilder csb = new FbConnectionStringBuilder();
  23. csb.ServerType = FbServerType.Embedded;
  24. csb.Database = "mydb.fdb";
  25. csb.UserID = "SYSDBA";
  26. csb.Password = "masterkey";
  27.  
  28. string conString = csb.ToString();
  29. FbConnection.CreateDatabase(conString);
  30.  
  31. FbScript script = new FbScript("DB_GEN.sql");
  32. script.Parse();
  33.  
  34. using (FbConnection conn = new FbConnection(conString))
  35. {
  36.     conn.Open();
  37.     Console.WriteLine("Connection opened");
  38.  
  39.     FbBatchExecution fbe = new FbBatchExecution(conn);
  40.  
  41.     foreach (string cmd in script.Results) {
  42.         fbe.SqlStatements.Add(cmd);
  43.     }
  44.  
  45.     try {
  46.         fbe.Execute();
  47.     }catch(Exception e)
  48.     {
  49.         Console.WriteLine(e.Message);
  50.     }
  51.  
  52.     conn.Close();
  53.  
  54.     Console.WriteLine("Connection closed");
  55.  
  56.     Console.WriteLine("Press any key to continue . . . ");
  57.     Console.ReadKey(true);
  58. }
  59.        
  60. FbScript script = new FbScript("DB_GEN.sql");
  61.        
  62. StreamReader sr = File.OpenText(@"C:TEMPDB_GEN.sql");
  63. FbScript script = new FbScript(sr.ReadToEnd());