我是编程新手,我遇到了一个问题。我正在调用一个表,需要将我的结果放入某个路径中的csv文件中。
这就是我正在做的和我得到的错误。
dbuser@cbos1:/var/lib/dbspace/bosarc/testing/Abe_Lincoln> cd dbaccess labor32<<?
> UNLOAD TO '/var/lib/dbspace/bosarc/Active_Sites/Cronos_test/Position7'
> select * from informix.position;
> ?
-bash: cd: dbaccess: No such file or directory
dbuser@cbos1:/var/lib/dbspace/bosarc/testing/Abe_Lincoln>
文件路径存在,但不断收到消息。
答案 0 :(得分:3)
Using just public sealed class LambdaParser : ExpressionVisitor
{
public List<BinaryExpression> Expressions { get; } = new List<BinaryExpression> ();
protected override Expression VisitBinary (BinaryExpression node)
{
Expressions.Add (node);
return base.VisitBinary (node);
}
public bool MathEquals (LambdaParser g)
{
try
{
return MathEquals (Expressions, g.Expressions);
} catch (Exception e)
{
throw new Exception ("MathEquals", e);
}
}
public static bool MathEquals (List<BinaryExpression> f, List<BinaryExpression> g)
{
//handle simple cases
if (ReferenceEquals (f, g))
return true;
if (f == null || g == null)
return false;
if (f.Count == 0 || g.Count == 0)
return false;
try
{
//handle single one element cases
if (f.Count == 1 && g.Count == 1)
{
return MathEquals (f[0], g[0]);
}
} catch (Exception e)
{
throw new Exception ("MathEquals", e);
}
throw new NotImplementedException ("Math Equals");
}
static bool MathEquals (BinaryExpression f, BinaryExpression g)
{
if (ReferenceEquals (f, g))
return true;
if (f == null || g == null)
return false;
if (f.NodeType != g.NodeType)
return false;
try
{
switch (f.NodeType)
{
case ExpressionType.Add:
case ExpressionType.Multiply:
return CompareCommutative (f, g);
case ExpressionType.Subtract:
case ExpressionType.Divide:
case ExpressionType.Modulo:
return CompareNonCommutative (f, g);
default:
throw new NotImplementedException ($"Math Equals {nameof(f)}: {f.NodeType}, {nameof(g)}: {g.NodeType}");
}
} catch (Exception e)
{
throw new Exception ($"MathEquals {nameof(f)}: {f.NodeType}, {nameof(g)}: {g.NodeType}", e);
}
}
static bool IsParam (Expression f)
{
return f.NodeType == ExpressionType.Parameter;
}
static bool IsConstant (Expression f)
{
return f.NodeType == ExpressionType.Constant;
}
static bool CompareCommutative (BinaryExpression f, BinaryExpression g)
{
bool left, right;
try
{
//parse left f to left g and right g
left = CompareParamOrConstant (f.Left, g.Left) || CompareParamOrConstant (f.Left, g.Right);
//parse right f to left g and right g
right = CompareParamOrConstant (f.Right, g.Left) || CompareParamOrConstant (f.Right, g.Right);
return left && right;
} catch (Exception e)
{
throw new Exception ($"CompareCommutative {nameof(f)}: {f.NodeType}, {nameof(g)}: {g.NodeType}", e);
}
}
static bool CompareNonCommutative (BinaryExpression f, BinaryExpression g)
{
bool left, right;
try
{
//compare f left to g left
left = CompareParamOrConstant (f.Left, g.Left);
//compare f right to f right
right = CompareParamOrConstant (f.Right, g.Right);
} catch (Exception e)
{
throw new Exception ($"CompareNonCommutative {nameof(f)}: {f.NodeType}, {nameof(g)}: {g.NodeType}", e);
}
return left && right;
}
static bool CompareParamOrConstant (Expression f, Expression g)
{
var ParamF = IsParam (f);
var ConstantF = IsConstant (f);
if (!(ParamF || ConstantF))
{
throw new ArgumentException ($"{nameof(f)} is neither a param or a constant", $"{nameof(f)}");
}
var ParamG = IsParam (g);
var ConstantG = IsConstant (g);
if (!(ParamG || ConstantG))
{
throw new ArgumentException ($"{nameof(g)} is neither a param or a constant", $"{nameof(g)}");
}
if (ParamF)
{
return ParamG;
}
if (ConstantF)
{
return ConstantG && (f as ConstantExpression).Value.Equals ((g as ConstantExpression).Value);
}
}
}
as the command line prompt, you should be using just:
$
This will run the $ dbaccess labor32 <<?
> UNLOAD TO '/var/lib/dbspace/bosarc/Active_Sites/Cronos_test/Position7'
> select * from informix.position;
> ?
…message(s) from dbaccess
$
program (usually from dbaccess
) against the database $INFORMIXDIR/bin
, and generate an UNLOAD format file in the given file name.
The labor32
command is for changing directory; you don't have a directory called cd
(and probably shouldn't), and even if you did have such a directory, you shouldn't provide more options to the dbaccess
command, or a here document as standard input — it will ignore them.
Note that the file generated (cd
will be the base name of the file) will be in Informix's UNLOAD format (pipe delimited fields by default), not CSV. It's certainly possible to convert between the two; I have Perl scripts that can do the conversions — last modified about a decade ago, but not much has changed in the interim. You could also consider using SQLCMD (available as open source from the IIUG Software Repository) which does have support for CSV load and unload formats. (This is the original SQLCMD — or at least an original SQLCMD — and is not Microsoft's Johnny-come-lately program of the same name.)
Create a file Position7
containing:
unload-table.sh
You can then run this as #!/bin/sh
dbaccess labor32 <<EOF
UNLOAD TO '/var/lib/dbspace/bosarc/Active_Sites/Cronos_test/Position7'
SELECT * FROM informix.position;
EOF
, or make it executable and install it in your bash unload-table.sh
directory (which is on your PATH, isn't it?) so that you can simply run $HOME/bin
. Or you can arrange to 'compile' (copy) the file to unload-table.sh
(no unload-table
suffix) so you don't have to type it to execute it: .sh
. You can enhance the script to allow the program (unload-table
), database (dbacess
), table (labor32
) and file (informix.position
) to be set as command line arguments or via environment variables. That requires a bit of fiddling in the script, but nothing outrageous. I'd probably allow the file name to be specified separately from the directory where the file is to be stored so that it is easier to configure on the command line.