Я снова сломал ядро ​​СУБД Access?

При тестировании приведенного ниже кода SQL для другого ответа на переполнение стека я получил следующие ошибки:

  • mdb через OLE DB: «Катастрофический сбой»
  • accdb через OLE DB: (пустое сообщение)
  • Объект запроса Access2007: «Неизвестная ошибка базы данных Access»

Я использую новый чистый файл базы данных. showplan.out план выполнения не содержит ничего полезного; Я разместил содержание ниже.

Могу ли я что-нибудь сделать, кроме объявления Access Database Engine непригодным для использования (!!)?

Sub Discon()

  Const USE_MDB As Long = 1
  Const USE_ACCDB As Long = 2

  Dim version As Long

  ' Hard code which version of the
  ' Access Database Engine to use

  version = USE_MDB

  Dim fullFileName As String
  Dim conString As String

  If version = USE_MDB Then

    fullFileName = Environ$("temp") & "\DropMe.mdb"
    conString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & fullFileName

  Else

    fullFileName = Environ$("temp") & "\DropMe.accdb"
    conString = _
        "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & fullFileName

  End If

  On Error Resume Next
  Kill fullFileName
  On Error GoTo 0

  Dim cat
  Set cat = CreateObject("ADOX.Catalog")
  With cat

    ' Create a new database file in user's temp folder
    .Create conString

    With .ActiveConnection

      Dim Sql As String

      ' Create a new base base with data (required to
      ' be able to later create a virtual table)

      Sql = _
      "CREATE TABLE Customers (" & _
      "CustomerID CHAR(5) NOT NULL UNIQUE);"
      .Execute Sql

      Sql = _
      "INSERT INTO Customers (CustomerID)" & _
      " VALUES ('ANTON');"
      .Execute Sql

      ' Create a virtual (viewed) table
      Sql = _
      "CREATE VIEW TableA AS  " & _
      "SELECT DT1.ID, DT1.[Date], DT1.Supplier_ID " & _
      "FROM ( " & _
      "      SELECT DISTINCT 1 AS ID, '2009-10-23 00:00:00' AS [Date], " & _
      "             1 AS Supplier_ID FROM Customers " & _
      "      UNION ALL  " & _
      "      SELECT DISTINCT 2, '2009-10-23 00:00:00', 1 FROM Customers" & _
      "      UNION ALL  " & _
      "      SELECT DISTINCT 3, '2009-10-24 00:00:00', 2 FROM Customers " & _
      "      UNION ALL  " & _
      "      SELECT DISTINCT 4, '2009-10-25 00:00:00', 2 FROM Customers " & _
      "      UNION ALL  " & _
      "      SELECT DISTINCT 5, '2009-10-26 00:00:00', 1  FROM Customers " & _
      "     ) AS DT1;"
      .Execute Sql

      ' Create VIEWs based on the virtual table

      Sql = _
      "CREATE VIEW TableA_StartDates (Supplier_ID, start_date) " & _
      "AS " & _
      "SELECT T1.Supplier_ID, T1.[Date] " & _
      "  FROM TableA AS T1 " & _
      " WHERE NOT EXISTS ( " & _
      "                   SELECT * " & _
      "                     FROM TableA AS T2 " & _
      "                    WHERE T2.Supplier_ID = T1.Supplier_ID " & _
      "                          AND DATEADD('D', -1, T1.[Date]) = T2.[Date] " & _
      "                  );"
      .Execute Sql

      Sql = _
      "CREATE VIEW TableA_EndDates (Supplier_ID, end_date) " & _
      "AS " & _
      "SELECT T3.Supplier_ID, T3.[Date] " & _
      "  FROM TableA AS T3 " & _
      " WHERE NOT EXISTS ( " & _
      "                   SELECT * " & _
      "                     FROM TableA AS T4 " & _
      "                    WHERE T4.Supplier_ID = T3.Supplier_ID " & _
      "                          AND DATEADD('D', 1, T3.[Date]) = T4.[Date] " & _
      "                  );"
      .Execute Sql

      Sql = _
      "CREATE VIEW TableA_Periods (Supplier_ID, start_date, end_date) " & _
      "AS " & _
      "SELECT DISTINCT T5.Supplier_ID, " & _
      "       ( " & _
      "        SELECT MAX(S1.start_date) " & _
      "          FROM TableA_StartDates AS S1 " & _
      "         WHERE S1.Supplier_ID = T5.Supplier_ID " & _
      "               AND S1.start_date <= T5.[Date] " & _
      "       ), " & _
      "       ( " & _
      "        SELECT MIN(E1.end_date) " & _
      "          FROM TableA_EndDates AS E1 " & _
      "         WHERE E1.Supplier_ID = T5.Supplier_ID " & _
      "               AND T5.[Date] <= E1.end_date " & _
      "       )         " & _
      "  FROM TableA AS T5;"
      .Execute Sql

      ' Attempt to use the nested VIEWs in a query

      Sql = _
      "SELECT * FROM TableA_Periods AS P1;"

      Dim rs

      On Error Resume Next
      Set rs = .Execute(Sql)

      If Err.Number = 0 Then
        MsgBox rs.GetString
      Else
        MsgBox _
            Err.Number & ": " & _
            Err.Description & _
            " (" & Err.Source & ")"
      End If

      On Error GoTo 0

    End With
    Set .ActiveConnection = Nothing
  End With
End Sub

Это содержимое showplan.out:

--- temp query ---

- Inputs to Query -
- End inputs to Query -

01) Insert into 'Customers'



--- temp query ---

- Inputs to Query -
- End inputs to Query -

01) Insert into 'Customers'



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
05) Restrict rows of result of 04)
      by scanning
      testing expression "Not "



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
05) Restrict rows of result of 04)
      by scanning
      testing expression "Not "



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
05) Restrict rows of result of 04)
      by scanning
      testing expression "Not "



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
05) Restrict rows of result of 04)
      by scanning
      testing expression "Not "



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
      store result in temporary table



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
      store result in temporary table



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
      store result in temporary table



--- temp query ---

- Inputs to Query -
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
Table 'Customers'
- End inputs to Query -

      store result in temporary table
      store result in temporary table
01) Union result of '00)' and result of '00)'
      store result in temporary table
02) Union result of '01)' and result of '01)'
      store result in temporary table
03) Union result of '02)' and result of '02)'
      store result in temporary table
04) Union result of '03)' and result of '03)'
      store result in temporary table

person onedaywhen    schedule 21.10.2009    source источник
comment
+1 за заголовок вашего вопроса, так как он заставил меня смеяться, но, к сожалению, я не могу помочь, так как я, к сожалению, оставил Access много лет назад.   -  person Richard Lucas    schedule 21.10.2009
comment
Это вещь Jet 4.0 или вы можете воспроизвести ее в более ранней версии?   -  person heferav    schedule 21.10.2009
comment
@heferav: можете ли вы воспроизвести его в более ранней версии? - Невозможно: более ранние версии не поддерживали CREATE VIEW и EXISTS. Это вещь Jet 4.0 - я могу воспроизвести ее в более поздней версии ACE, версии движка для Access2007.   -  person onedaywhen    schedule 21.10.2009
comment
Что вы пытаетесь сделать? Я, конечно, вообще не понимаю, что вы здесь пытаетесь протестировать. Мне кажется неестественным использовать DAO для создания хранилищ данных Jet / ACE из Access. Уравнение переходит в ADO, когда ваша среда разработки не является Access, но я просто не вижу оправдания для использования здесь уровня интерфейса неродных данных.   -  person David-W-Fenton    schedule 22.10.2009
comment
@ Дэвид В. Фентон: Что вы пытаетесь сделать - см. Ответ HansUp. Его анализ точен, т.е. «материализует» таблицу на лету. Объясняет лучше, чем я :)   -  person onedaywhen    schedule 22.10.2009
comment
@David W. Fenton: Мне кажется неестественным использовать DAO для создания хранилищ данных Jet / ACE из Access - действительно: вы предпочитаете дизайнер GUI командной строке или необработанному коду. Лошади на курсы;)   -  person onedaywhen    schedule 22.10.2009
comment
@David W. Fenton: Я просто не вижу оправдания для использования здесь уровня интерфейса неродных данных - это очень просто: мои навыки SQL и ADO намного перевешивают мои навыки DAO. Я предполагаю, что CREATE VIEW SQL DDL можно заменить манипулированием объектами QueryDef в DAO, а подзапрос EXISTS можно заменить синтаксисом соединения. Но я также не вижу оправдания тому, чтобы отдавать предпочтение DAO ... если только он не дает сбой, то есть! Может быть, вы могли бы сами попробовать перевод DAO ...?   -  person onedaywhen    schedule 22.10.2009
comment
@David W. Fenton: здесь используется уровень неродного интерфейса данных - я знаю, что вы его не понимаете, но провайдеры OLE DB, которые я использую, являются родными для ядра СУБД Access. Вы действительно хотите обсуждать это каждый раз, когда кто-то упоминает ADO в контексте ядра СУБД Access?   -  person onedaywhen    schedule 22.10.2009


Ответы (1)


Объявить ядро ​​СУБД Access непригодным для использования (!!). Это обычные запросы, которые должны работать без ошибок.

person onedaywhen    schedule 22.09.2010
comment
полностью согласен. Я ненавижу MS Access / Jet. Мне нравятся проекты данных Access, которые являются более эффективным способом связи между SQL Server и MS Access. Я очень рад новому поколению настоящего клиент-серверного программного обеспечения от MS Access 2013. - person Aaron Kempf; 11.10.2012
comment
@AaronKempf: Аарон, так приятно снова тебя слышать. Мы обменивались выстрелами в течение многих лет, и это может быть один из немногих случаев, когда мы пришли к согласию. Чтобы узнать больше о памяти, см. Это: mofeel.net/1-microsoft-public-access-adp-sqlserver/2808-3.aspx - person onedaywhen; 05.11.2012
comment
да .. Я сейчас стараюсь быть немного более красноречивым :) - person Aaron Kempf; 06.11.2012