Ruby,MS Access - 不同的查询结果

时间:2013-12-12 00:06:56

标签: ruby ms-access

我定期向MS Access数据库提交一些表和相应的数据。我正在Ruby(1.9.3)中编写一个脚本来查询该数据库以获取我需要的信息,然后迭代结果以生成其他数据。

我注意到Ruby中与MS Access中完全相同的sql字符串不会返回相同的数据集,但我无法弄清楚原因。

我看到的有限数量的其他问题都与我在SQL中不存在的“where”条件或SQL中的变量(也不存在)有关。它是一个固定的文本字符串,如果我将其粘贴到Access并运行,它将返回559,283行数据,但如果我运行Ruby WIN32OLE连接,它只返回69,773行数据(559,283集中确实存在)。 / p>

这是一个复杂的连接,但因为它是两个位置之间的相同SQL字符串,所以我不知道为什么会有不同的结果。

OLE连接和SQL语句:( ACES车辆增强标准数据库,以防任何人熟悉它)

connection = WIN32OLE.new('ADODB.Connection')
connection.open('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<redacted>.accdb')

recordset = WIN32OLE.new('ADODB.Recordset')
sql = "SELECT Vehicle.VehicleID, BaseVehicle.BaseVehicleID, BaseVehicle.YearID, Make.MakeName, Model.ModelName, SubModel.SubModelName, EngineConfig.EngineConfigID, EngineBase.Liter, EngineBase.Cylinders, EngineBase.BlockType, CylinderHeadType.CylinderHeadTypeName, EngineDesignation.EngineDesignationName, FuelType.FuelTypeName, TransmissionNumSpeeds.TransmissionNumSpeeds, TransmissionControlType.TransmissionControlTypeName, TransmissionMfrCode.TransmissionMfrCode, DriveType.DriveTypeName, VehicleToTransmission.TransmissionID FROM TransmissionControlType INNER JOIN (FuelType INNER JOIN (EngineBase INNER JOIN (CylinderHeadType INNER JOIN (EngineDesignation INNER JOIN (DriveType INNER JOIN (TransmissionMfrCode INNER JOIN (TransmissionNumSpeeds INNER JOIN (TransmissionBase INNER JOIN (Transmission INNER JOIN ((((SubModel INNER JOIN ((Model INNER JOIN (Make INNER JOIN BaseVehicle ON Make.MakeID = BaseVehicle.MakeID) ON Model.ModelID = BaseVehicle.ModelID) INNER JOIN Vehicle ON BaseVehicle.BaseVehicleID = Vehicle.BaseVehicleID) ON SubModel.SubModelID = Vehicle.SubModelID) INNER JOIN VehicleToDriveType ON Vehicle.VehicleID = VehicleToDriveType.VehicleID) INNER JOIN (EngineConfig INNER JOIN VehicleToEngineConfig ON EngineConfig.EngineConfigID = VehicleToEngineConfig.EngineConfigID) ON Vehicle.VehicleID = VehicleToEngineConfig.VehicleID) INNER JOIN VehicleToTransmission ON Vehicle.VehicleID = VehicleToTransmission.VehicleID) ON Transmission.TransmissionID = VehicleToTransmission.TransmissionID) ON TransmissionBase.TransmissionBaseID = Transmission.TransmissionBaseID) ON TransmissionNumSpeeds.TransmissionNumSpeedsID = TransmissionBase.TransmissionNumSpeedsID) ON TransmissionMfrCode.TransmissionMfrCodeID = Transmission.TransmissionMfrCodeID) ON DriveType.DriveTypeID = VehicleToDriveType.DriveTypeID) ON EngineDesignation.EngineDesignationID = EngineConfig.EngineDesignationID) ON CylinderHeadType.CylinderHeadTypeID = EngineConfig.CylinderHeadTypeID) ON EngineBase.EngineBaseID = EngineConfig.EngineBaseID) ON FuelType.FuelTypeID = EngineConfig.FuelTypeID) ON TransmissionControlType.TransmissionControlTypeID = TransmissionBase.TransmissionControlTypeID;"
recordset.Open(sql, connection)
cars = recordset.GetRows.transpose

cars.length =&gt; 69773

粘贴到Access中的精确sql字符串:559,283行。

我在我的Ruby环境中使用Aptana Studio 3,在Win7 64bit上运行

有什么想法吗?

编辑: 另外,这不是对连接的限制,因为我有第二个查询通过Ruby从同一个数据库返回521,000行,直接通过Access返回516,000行。

所有查询在Access与Ruby

之间的运行时间大致相同

0 个答案:

没有答案