我想打印特定会话生成并发送到数据库的代码。我见过这个问题,但它与 SQLAlchemy 生成的所有 SQL 相呼应。我只想要代表特定会话生成的 SQL。如果它可以在实际发送到数据库之前打印,则加分(就像我们可以使用 Query 对象)
我知道我可以打印查询的 SQL,但在这种情况下
a = Table(id=1)
session.add(a)
b = Table(id=4)
session.add(a)
b.column = 5
session.commit()
Run Code Online (Sandbox Code Playgroud)
没有要打印的查询,但会话正在开始事务、插入行并提交事务。
我希望会话打印到标准输出(或文件,如果不可能的话)它发送到数据库的 SQL 命令。
我希望在控制台中找到的(虚构的)SQL 是
BEGIN TRANSACTION
INSERT INTO Table (id) VALUES (1);
INSERT INTO Table (id, column) VALUES (4,5);
COMMIT TRANSACTION
Run Code Online (Sandbox Code Playgroud)
我完全理解这些行可能不会全部合并在一起,并且可能会被其他代码打印交错(会话首先开始事务,然后代码触发插入的刷新,并且作为最后一件事会话发出提交)
那可能吗?
我正在尝试使用 SQLAlchemy 核心来创建一个查询,该查询仅在 DB(postgres) 中命中一次,并在它不存在时插入一行。
这是查询的一部分
WITH new_values (id, field) as (
values
(1, 1),
(2, 12),
(3, 13),
(4, 14)
)
INSERT INTO table1 (id, field)
SELECT id, field
FROM new_values
WHERE NOT EXISTS (SELECT 1
FROM table1 as up
WHERE up.id = new_values.id);
Run Code Online (Sandbox Code Playgroud)
我很困惑:
SELECT 1?我想使用核心 API 并避免直接执行。
PS:我想放在单个事务中的完整查询是
WITH upsert AS (
UPDATE table2
SET field1=field1+1
WHERE id=1234 AND field2=42
RETURNING *
)
INSERT INTO table2 (id, field1, field2) …Run Code Online (Sandbox Code Playgroud) 从 git gui 开始,我在当前提交之前使用 gitkgit reset -hard进行了一些提交,因为我需要测试更改之前一切是否正常。
由于我什至有一些未提交的更改,因此我git stash为了保存它们并能够在返回到上次提交后重新应用它们。
问题是 gitk 不再显示我的提交树的顶部(顶部提交是当前提交,我没有看到上面有任何提交)
有时自从我上次使用 git 以来,但我想我可以使用 git reset -hard 将当前代码带到以前的版本,然后 git reset -hard 到旧版本。
如何检索旧 HEAD 和修订版之间的所有提交git reset -hard?请告诉我有某种方法。
我使用 Eclipse 作为开发工具(以防我需要使用它的缓存)
编辑 3
我有一些从 python 访问的 C++ 代码(externed 为 C)。我想double**在 python 中分配一个,将它传递给 C/C++ 代码以复制类内部数据的内容,然后在 python 中使用它,类似于我将如何使用列表列表。
不幸的是,我无法为 python 指定最内部数组的大小,因此它在迭代它和程序段错误时读取无效内存。
我无法在 C++ 中更改内部数据的结构,我想让 python 为我做边界检查(就像我使用的是 c_double_Array_N_Array_M 而不是指针数组)。
test.cpp(用 编译g++ -Wall -fPIC --shared -o test.so test.cpp)
#include <stdlib.h>
#include <string.h>
class Dummy
{
double** ptr;
int e;
int i;
};
extern "C" {
void * get_dummy(int N, int M) {
Dummy * d = new Dummy();
d->ptr = new double*[N];
d->e = N;
d->i = M;
for(int i=0; i<N; …Run Code Online (Sandbox Code Playgroud) 从 makefile 执行命令时,我不知道如何转义美元符号以访问在 docker 环境中定义的变量。
这是我的设置的最小表示,我正在尝试回应 /mypath
define create-test
so-test-$1:
docker run \
--rm \
-t \
--env SRC="/mypath" \
ubuntu:xenial \
/bin/bash -c "$2"
endef
$(eval $(call create-test,1,echo $SRC ))
$(eval $(call create-test,2,echo $$SRC ))
$(eval $(call create-test,3,echo $$$$SRC ))
$(eval $(call create-test,4,echo $$$$$$$$SRC ))
Run Code Online (Sandbox Code Playgroud)
输出是
$ make so-test-1
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo RC "
RC
$ make so-test-2
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo RC "
RC
$ …Run Code Online (Sandbox Code Playgroud) 几个月前我已经看了一下dedengine,我设法做了一些事情.现在我下载了最新版本,我最简单的事情就是崩溃了.在这里我的代码
package francesco.mygame;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
public class mainMenu extends BaseGameActivity
{
// ===========================================================
// Constants
// ===========================================================
static final int CAMERA_WIDTH = 480;
static final int CAMERA_HEIGHT = 320;
//private static final String TAG = "Main Menu";
// ===========================================================
// Fields
// ===========================================================
protected Camera mCamera;
protected BitmapTextureAtlas mTexture;
protected TextureRegion mPlayTexture;
protected Sprite …Run Code Online (Sandbox Code Playgroud)