返回的logging集closures(在DBA中通过ODBC访问mysql数据库)

长时间的观众第一次的海报。 我正在使用Excel中的前端工作数据库应用程序。 因此我使用VBA来访问MySQL数据库。 我使用的驱动程序是ODBC驱动程序(Windows),我有一个有效的连接到数据库,因为许多其他查询function良好。

我想要做的是从一系列SQL语句中返回结果,而不是试图将其全部结合成一个大规模的语句(这可能会起作用,但难以维护/理解)。 我已经将FLAG_MULTI_STATEMENTS = 67108864标志添加到了抑制驱动程序语法错误的连接string中。

但现在当我运行以下:

 queryDB.Open SQLquery, conn 

recordset (queryDB)保持closures,没有明显的错误。 sql语句可以在这里find。

我可能会产生不返回到VBA的错误,所以在这里的任何帮助将不胜感激。

:sql语句工作,因为我可以将该语句粘贴到phpMyAdmin ,它会返回正确(非空)的结果。 我不知道这些语句是否具体是问题,但可能是使用CREATE TEMPORARY TABLE ...或者使用多个语句。

另外我猜测,驱动程序可能试图返回每个SQL语句的结果和VBA只得到第一个或东西…

编辑 :SQL语句供将来参考。

 CREATE TEMPORARY TABLE tmpOrders AS SELECT o.customerName, SUM(o.Sales) AS Sales, SUM(TotalFobCost + TotalLandedCost + TotalLocalCost + TotalCmtCost) AS TotalCost, YEAR(o.deliveryDate) AS YEAR, MONTH(o.deliveryDate) AS MONTH FROM devere_costing.orders_fixed_extras AS o WHERE o.orderApproved = TRUE AND o.orderCanceled = FALSE AND o.deliveryDate BETWEEN '2014-01-01' AND '2014-03-31' GROUP BY customerName, YEAR, MONTH ORDER BY YEAR ASC, MONTH ASC, customerName ASC; CREATE TEMPORARY TABLE tmpProj AS SELECT p.customerName, IF(p.MONTH > 9, p.YEAR, p.YEAR - 1) AS TrueYear, 1 + ((p.MONTH + 2) MOD 12) AS TrueMonth, SUM(p.actualSalesInvoiced) AS salesInvoiced, SUM(p.budget) AS budget FROM devere_costing.sales_projection_data AS p GROUP BY p.customerName, p.YEAR, p.MONTH HAVING TrueYear BETWEEN YEAR('2014-01-01') AND YEAR('2014-03-31') AND TrueMonth BETWEEN MONTH('2014-01-01') AND MONTH('2014-03-31'); CREATE TEMPORARY TABLE tmpLeft AS SELECT IF(o.customerName IS NULL, p.customerName, o.customerName) AS customerName, p.budget AS TotalBudget, o.Sales AS Sales, p.salesInvoiced, 0 AS varianceToBudget, o.TotalCost, 0 AS directMargin, 0 AS directMarginPercent, IF(o.YEAR IS NULL, p.TrueYear, o.YEAR) AS YEAR, IF(o.MONTH IS NULL, p.TrueMonth, o.MONTH) AS MONTH FROM tmpOrders AS o LEFT JOIN tmpProj AS p ON (o.customerName = p.customerName AND o.YEAR = p.TrueYear AND o.MONTH = p.TrueMonth); CREATE TEMPORARY TABLE tmpRight AS SELECT IF(o.customerName IS NULL, p.customerName, o.customerName) AS customerName, p.budget AS TotalBudget, o.Sales AS Sales, p.salesInvoiced, 0 AS varianceToBudget, o.TotalCost, 0 AS directMargin, 0 AS directMarginPercent, IF(o.YEAR IS NULL, p.TrueYear, o.YEAR) AS YEAR, IF(o.MONTH IS NULL, p.TrueMonth, o.MONTH) AS MONTH FROM tmpOrders AS o RIGHT JOIN tmpProj AS p ON (o.customerName = p.customerName AND o.YEAR = p.TrueYear AND o.MONTH = p.TrueMonth); (SELECT * FROM tmpLeft) UNION DISTINCT (SELECT * FROM tmpRight); 

我已经回答了我自己的问题!

秘密就在这里 :

所以我是对的,有一个以上的logging集返回。 我只需要遍历它们来find我想要的数据。 该集合没有索引,所以你必须search每一个。 在我的情况下,每个sql语句不会返回一个logging集(这就是为什么当我试图打开它时,我的logging集保持closures状态)。 唯一的例外是返回logging的最后一个sql语句。 我的循环如下所示:

 Dim rs As ADODB.Recordset Set rs = queryDB(Sql) ' Loop through returned recordsets to find the data Do If Not rs Is Nothing Then If rs.State = adStateOpen Then ' we have an open recordset. This means that the final select statement ' has returned this data. Exit Do Else ' Otherwise iterate through to the next recordset Set rs = rs.NextRecordset End If Else MsgBox "No recordset returned by sql statement" GoTo ExitCode End If Loop 

从问题主体复制的答案:

我已经回答了我自己的问题!

秘密就在这里 :

所以我是对的,有一个以上的logging集返回。 我只需要遍历它们来find我想要的数据。 该集合没有索引,所以你必须search每一个。 在我的情况下,每个sql语句不会返回一个logging集(这就是为什么当我试图打开它时,我的logging集保持closures状态)。 唯一的例外是返回logging的最后一个sql语句。 我的循环如下所示:

 Dim rs As ADODB.Recordset Set rs = queryDB(Sql) ' Loop through returned recordsets to find the data Do If Not rs Is Nothing Then If rs.State = adStateOpen Then ' we have an open recordset. This means that the final select statement ' has returned this data. Exit Do Else ' Otherwise iterate through to the next recordset Set rs = rs.NextRecordset End If Else MsgBox "No recordset returned by sql statement" GoTo ExitCode End If Loop