复杂的MySQL查询返回的字段的需求字段(列)类型信息

时间:2018-07-26 00:05:11

标签: php mysql

我花了很多时间在寻找解决方案,但找不到任何功能,功能或手段来有效确定复杂的MySQL查询返回的每个字段的类型。

例如:

SELECT CONCAT(`u`.`firstName`,' ',`u`.`lastName`) AS `userName`,
       CONCAT(`u`.`lastName`,', ',`u`.`firstName`) AS `userNameReversed`,
       `u`.*,`p`.`street`,`a`.`name` AS `unit`,`ct`.`name` AS `city` ,`p`.`postalCode`,
       `o`.`companyName`,`o`.`ownerId` AS `coOwnerId`,`o`.`addressId`,`o`.`email` AS `coEmail`
FROM `users` AS `u`
       LEFT JOIN `companies` AS `o` ON `u`.`companyId`=`o`.`id`
       LEFT JOIN `units` AS `a` ON `o`.`addressId`=`a`.`id`
       LEFT JOIN `properties` AS `p` ON `a`.`addressId`=`p`.`id`
       LEFT JOIN `cities` AS `ct` ON `p`.`cityId`=`ct`.`id`
WHERE (`u`.`id`=3)

其中通过php脚本返回如下XML结果:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<infoExchange>
   <session id='1142882141'>
      <get count='4'>
         <auth_token>0xfd8fdaaad7adad7ee9a9addf7f7bfcd9</auth_token>
         <key>1142882141</key>
         <cmd>fetchUser</cmd>
         <recId>3</recId>
      </get>
      <id>15325598331</id>
      <company id='1'>My Little Company Inc</company>
      <user id='1'>david white</user>
   </session>
   <query>SELECT CONCAT(`u`.`firstName`,' ',`u`.`lastName`) AS `userName`, CONCAT(`u`.`lastName`,', ',`u`.`firstName`) AS `userNameReversed`, `u`.*,`p`.`street`,`a`.`name` AS `unit`,`ct`.`name` AS `city` ,`p`.`postalCode`, `o`.`companyName`,`o`.`ownerId` AS `coOwnerId`,`o`.`addressId`,`o`.`email` AS `coEmail` FROM `users` AS `u` LEFT JOIN `companies` AS `o` ON `u`.`companyId`=`o`.`id` LEFT JOIN `units` AS `a` ON `o`.`addressId`=`a`.`id` LEFT JOIN `properties` AS `p` ON `a`.`addressId`=`p`.`id` LEFT JOIN `cities` AS `ct` ON `p`.`cityId`=`ct`.`id` WHERE (`u`.`id`=3) LIMIT 1</query>
   <data rowCount='1'>
      <colGroup count='16'>
         <column>id</column>
         <column>firstName</column>
         <column>lastName</column>
         <column>userName</column>
         <column>userNameReversed</column>
         <column>email</column>
         <column>rank</column>
         <column>isLocked</column>
         <column>street</column>
         <column>unit</column>
         <column>city</column>
         <column>postalCode</column>
         <column>companyId</column>
         <column>companyName</column>
         <column>coEmail</column>
         <column>lastOn</column>
      </colGroup>
      <row cellCount='16' index='0'>
         <item id='id'>3</item>
         <item id='firstName'>john</item>
         <item id='lastName'>doe</item>
         <item id='userName'>john doe</item>
         <item id='userNameReversed'>doe, john</item>
         <item id='email'>john.doe@gmail.com</item>
         <item id='rank'>500</item>
         <item id='isLocked'>0</item>
         <item id='street'>123 Anyold Street</item>
         <item id='unit'></item>
         <item id='city'>Anytown</item>
         <item id='postalCode'>H0H0H0</item>
         <item id='companyId'>3</item>
         <item id='companyName'>ACME Companies Inc.</item>
         <item id='coEmail'>mailbox@acme.com</item>
         <item id='lastOn'>2001-01-01 15:48:00</item>
      </row>
   </data>
</infoExchange>

我们真正想要的是,在COLGROUP块所描绘的XML的该部分中,还包括该字段的列类型。

据我所知,要获取该查询的字段(列)类型信息,我必须针对每个引用的引用构造并执行一系列单独的,专门定义的“ SELECT FIELDS”查询表格(我什至不知道如何获得由CONCAT操作创建的人工“列”的类型)。

当然,由于迫切需要将数据馈送到需要能够正确解释该数据的应用程序中,因此查询结果有一种简单的方法可以使接收方知道接收者正在传输的信息是什么类型,对吗? / p>

作为其他参考,SQL引擎是MySQL〜5,中间人是附加的Web服务器上的一系列PHP5脚本,最终客户端应用程序是C#(7.2)Windows-Forms应用程序。

0 个答案:

没有答案