在Sybase SQL中,我想执行包含SQL的String.
我希望这样的东西能起作用
declare @exec_str char(100)
select @exec_str = "select 1"
execute @exec_str
go
Run Code Online (Sandbox Code Playgroud)
执行| EXEC
Run Code Online (Sandbox Code Playgroud)is used to execute a stored procedure or an extended stored程序(ESP).如果批处理中有多个语句,则必须使用此关键字.
execute也用于执行包含Transact-SQL的字符串.
但是我上面的例子给出了一个错误.难道我做错了什么?
我想知道在C中如何将一个函数的内容复制到memroy并执行它?
我正在尝试做这样的事情:
typedef void(*FUN)(int *);
char * myNewFunc;
char *allocExecutablePages (int pages)
{
template = (char *) valloc (getpagesize () * pages);
if (mprotect (template, getpagesize (),
PROT_READ|PROT_EXEC|PROT_WRITE) == -1) {
perror ("mprotect");
}
}
void f1 (int *v) {
*v = 10;
}
// allocate enough spcae but how much ??
myNewFunc = allocExecutablePages(...)
/* Copy f1 somewere else
* (how? assume that i know the size of f1 having done a (nm -S foo.o))
*/
((FUN)template)(&val);
printf("%i",val);
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答
我正在尝试创建一个引用PostgreSQL 8.4中的临时表的函数.基于我的研究,似乎最好的方法是使用EXECUTE命令从定义的字符串执行我的查询.
不幸的是,我在尝试创建函数时遇到奇怪的语法错误.
我目前的功能定义如下:
CREATE OR REPLACE FUNCTION example() RETURNS void AS $$
EXECUTE 'INSERT INTO table1 (col1, col2, col3) SELECT col1, col2, col3 from temp_table';
$$ LANGUAGE SQL;
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
ERROR: syntax error at or near "'INSERT INTO table1 (col1, col2, col3) SELECT col1, col2, col3 from temp_table'"
LINE 2: execute 'INSERT INTO table1 (col1, col2, col3) SELECT col1...
Run Code Online (Sandbox Code Playgroud)
无论字符串文字中的实际内容如何,我似乎都得到了同样的错误.
我的问题是,1)使用EXECUTE特性的正确语法是什么,2)是否有更好的方法来编写这样一个引用临时表的函数?
我有一个非常基本的问题,但在互联网上找不到答案.
在Powerpoint 2010中,我有一个宏,我想在每次打开Powerpoint文档时执行它.怎么做到这一点?
谢谢 !
代码示例;
$stmt = $db->prepare('SELECT u.username, u.display_name FROM users u WHERE u.id = :userId');
$stmt->bindValue(':userId', 10);
$stmt->execute();
Run Code Online (Sandbox Code Playgroud)
使用prepare - > execute.如果您确定查询将返回最多1行; 是否有一种简单的方法来查看查询是否确实返回了一行?我看到每个人都在'rowCount'上验证,但是有没有更清洁的方式?
本文:http://www.christiansouth.com/php/pdo-getting-started-part-2-pdostatement/ states;
如果查询成功则为TRUE,否则为FALSE.如果SQL出错,它只会返回FALSE.因此,如果SQL有效但不返回rowset,您仍将获得TRUE返回值.
这个陈述是否正确?因为php.net只谈到:
成功时返回TRUE,失败时返回FALSE.
所以,再次提出问题:
我不认为这是可能的,但我一直在使用:
Process p = Runtime.getRuntime().exec(command);
Run Code Online (Sandbox Code Playgroud)
在命令行上运行命令,但是现在我遇到了一个情况,即我正在运行的命令会询问一些用户输入,例如用户名.
这不能通过作为exec的命令的参数来解决,是否有任何方法可以将用户名传递给同一命令行实例并继续?
- -编辑 - -
我仍然无法让这个工作.这些是命令行上的步骤:
C:\someProgram.exe
Login:
Passowrd:
Run Code Online (Sandbox Code Playgroud)
所以我需要在运行时提示时传递登录名和密码.我得到的代码不起作用:
try {
String CMD = "\"C:\\someProgram\"";
Scanner scan = new Scanner(System.in);
ProcessBuilder builder = new ProcessBuilder(CMD);
builder.redirectErrorStream(true);
Process process = builder.start();
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(is));
OutputStream out = process.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
String line;
try {
while (scan.hasNext()) {
String input = scan.nextLine();
if (input.toLowerCase().startsWith("login")) {
writer.write("myUsername");
} else if(input.toLowerCase().startsWith("password")){
writer.write("myPassword");
}
writer.flush();
line …Run Code Online (Sandbox Code Playgroud) 我目前有一个目录(udir),它对所有用户只有读写权限。该目录包含两个文件(file1 & file2)
我最初虽然只需要(在目录上)写访问权限才能通过 (rm udir/file1) 删除/删除文件,但 rm 命令会让我拒绝访问。当我设置读取、写入和执行权限时,rm 命令起作用。
显然也需要执行访问,但为什么呢?
我认为对目录的执行访问是能够使其成为工作目录并搜索其内容并访问子目录。
我需要在 Visual Basic 中执行 cmd 命令。这并不难,但我需要在外部程序运行时给出一个参数。
F:\mysql-5.7.13-winx64\bin\mysqldump.exe -h <ip> -u <user> -p <database> > abcd.sql
Run Code Online (Sandbox Code Playgroud)
但执行后,程序会要求输入密码。那么我该怎么做呢?
问候,多米尼克
我尝试使用 RealDictCursor:
cur = conn.cursor(cursor_factory = psycopg2.extras.RealDictCursor)
cur.execute('SELECT * FROM items')
res = cur.fetchall()
print(res)
print(type(res[0]))
Run Code Online (Sandbox Code Playgroud)
但它不起作用。结果:
[RealDictRow([('id', 1), ('name', 'apple')]), RealDictRow([('id', 2), ('name', 'pen')])]
<class 'psycopg2.extras.RealDictRow'>
Run Code Online (Sandbox Code Playgroud)
我需要一个字典,输出如下:
[{"id": 1, "name": "apple"}, {"id": 2, "name": "pen"}]
<class 'dict'>
Run Code Online (Sandbox Code Playgroud)
是的,我知道我可以用循环来制作 dict for . 但是我的表有 10000 行,我需要快速显示 10000 个项目。(我认为周期为不是很快解决我的问题。是真的吗?你能给我一个建议,用最短的时间量非常快的解决我的问题)
我怎么才能得到它?
PS:我需要它用于 Flask 的 API 服务,所以在此之后我需要像这样返回它:
return jsonify({my_dictonary_sql_query})
Run Code Online (Sandbox Code Playgroud) execute ×10
postgresql ×2
basic ×1
c ×1
cmd ×1
command ×1
command-line ×1
copy ×1
delete-file ×1
file ×1
function ×1
java ×1
json ×1
macros ×1
memory ×1
mysql ×1
oracle ×1
pdo ×1
permissions ×1
php ×1
powerpoint ×1
psycopg2 ×1
python ×1
sql ×1
startup ×1
string ×1
sybase ×1
syntax-error ×1
temp-tables ×1
unix ×1