如何在sqllite中格式化表输出

问题描述 投票:0回答:2

如果我在 sqlite3 shell 中执行此操作,它会完美运行,但我想在我的 C++ 代码中执行此操作。 如果我使用回调函数来打印列,那么我不知道如何在 C++ 中传递“.mode”和“.header”参数以以下格式的方式打印表格。

以下代码来自此链接

sqlite> .mode column
sqlite> .headers on
sqlite> select * from foo;
bar         baz         baf
----------  ----------  ----------
234         kshitiz     dba.se
sqlite
2个回答
1
投票

.mode
.headers
是特定于 sqlite 可执行文件的命令,而不是可以在其他地方使用的 SQL 命令。所以你必须在代码中重现该行为,幸运的是这并不困难。

要从表中获取列名,您可以从

sqlite_master
读取,但还有其他方法。例如,查看这篇文章:如何从 Sqlite 数据库读取元数据


0
投票

uuid":"476DBD8D-DFAD-452B-A393-0B82E093C86B","newsfeedMessages":[],"devMode":fa lse,"deviceId":"","time":"1730785195.809344","reqId":"C5460A98-1F90-4D9F-97E4-1F 4A6631805D”,“操作”:“getVars”,“userId”:“”,“令牌”:“EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw”,“客户端”:“ios”,“sdkVersion”:“4.1.0”,“includeDefaults”:false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785192.916526”,“reqId”:“017128CC-D52D-4C3B-921D-C 684AD680A64","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个 …… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785192.909302”,“reqId”:“27D3663D-F449-4BD0-96E7-2 AEB02B5B759","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个…… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785148.969780”,“reqId”:“65201892-A8E4-4607-9293-B A7FBC028DB6","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785135.605720”,“reqId”:“39EA373C-16EC-4041-8FE1-4 F369A421642”,“操作”:“getVars”,“userId”:“”,“令牌”:“EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw”,“客户端”:“ios”,“sdkVersion”:“4.1.0”,“includeDefaults”:false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785106.345279”,“reqId”:“ED86CC94-80A7-4DF8-A072-B 4B20F4EFC7F","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785106.326079”,“reqId”:“6F137E76-7122-407D-8EC9-F 2384F65A038”,“操作”:“getVars”,“userId”:“”,“令牌”:“EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw”,“客户端”:“ios”,“sdkVersion”:“4.1.0”,“includeDefaults”:false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785082.102261”,“reqId”:“B0DA1CC7-A022-40A9-A997-E 9EB8F9CC060","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785081.404443”,“reqId”:“459C68FD-705E-4FCD-BB4F-A 5CE23E7D6F5","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785080.881985”,“reqId”:“39C4DD7E-BC3E-49E8-9477-E AD0CEDD9102","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”:f另外,“deviceId”:“”,“时间”:“1730785080.863259”,“reqId”:“3E9E6C35-8AC8-4C4F-9B2A-A 76B523CA86C","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false} ,一个… {“uuid”:“476DBD8D-DFAD-452B-A393-0B82E093C86B”,“newsfeedMessages”:[],“devMode”: false,"deviceId":"","时间":"1730785080.302527","reqId":"C4573F7E-9B9C-49F4-A77F- FFF009059EC7","操作":"getVars","userId":"","令牌":"EfjCOFPQQliauMBFZZPVABcNtMBCBUWVhW9YCbvvjiw","客户端":"ios","sdkVersion":"4.1.0","includeDefaults":false}

© www.soinside.com 2019 - 2024. All rights reserved.