简体   繁体   English

如何使用mysql命令行执行(通过ant)一组SQL文件

[英]How to execute (via ant) a set of sql files with mysql command line

I want to execute all sql files which resistes in a given directory. 我想执行抵抗给定目录中的所有sql文件。 The call i want to make is something like this: 我要拨打的电话是这样的:

mysql --host=dbbackend --user=stack --password=overflow dbname -e 'source file1.sql'

This can be expressed as: 可以表示为:

  <apply executable="mysql" dir="." failonerror="true">
      <arg value="--host=dbbackend"></arg>
      <arg value="--user=stack"></arg>
      <arg value="--password=overflow"></arg>
      <arg value="mydbname"></arg>
      <arg value="--e source dummy.sql"></arg>
      <fileset dir="${db.dump.location.data}" casesensitive="no" description="take all sql files">
          <patternset>
              <include name="**/*.sql" />
          </patternset>
      </fileset>
  </apply>

If i have 3 sql files in that dir, then dummy.sql is called 3 times. 如果我在该目录中有3个sql文件,则dummy.sql被调用3次。 So far so good. 到现在为止还挺好。 Is there a placeholder available to change this line: 是否可以使用占位符来更改此行:

      <arg value="--e source dummy.sql"></arg>

into: 变成:

      <arg value="--e source ${unknown.placeholder.name}"></arg>

If there is a placeholder, then i want to use it for the "input" attribute of the "apply" tag (and remove the argument "-e"). 如果有一个占位符,那么我想将其用于“ apply”标签的“ input”属性(并删除参数“ -e”)。

There is a "srcfile" tag available for the "apply" element, but i can not call this (does not work): 有一个“ srcfile”标签可用于“ apply”元素,但是我不能调用它(不起作用):

      <arg value="--e source"></arg>
      <srcfile/>

Do you have suggestions on how to do it with native ant declaration? 您是否对使用本机ant声明进行处理有任何建议? Is it possilbe to build a workaround using antcall+fileset (+placeholder)? 是否可以使用antcall + fileset(+ placeholder)构建替代方法?

The noobish workaround is to iterate via fileset and create a temp sql file with references to the sql files. 无用的解决方法是通过文件集进行迭代并使用对sql文件的引用创建一个临时sql文件。 As a last step: call it static via "-e". 最后一步:通过“ -e”将其称为static。 But that is a workaround that i want to remove (by this question). 但这是我要删除(通过此问题)的一种解决方法。

PS: I do not want to use ant-contrib features. PS:我不想使用ant-contrib功能。

Why not using the ant sql task , which is designed to do exactly what you want to do? 为什么不使用ant sql任务 ,该任务旨在准确地完成您想做的事情?

Else, you may use the srcfile nested element: 另外,您可以使用srcfile嵌套元素:

<apply ... parallel="false">
  <...>
  <arg value="--e source" />
  <srcfile/>
  <fileset ...></fileset>
</apply>

There is a complete example on the manual page of the apply task . apply任务手册页上有完整的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM