假设我们有一个联盟:
typedef union someunion {
int a;
double b;
} myunion;
Run Code Online (Sandbox Code Playgroud)
在设置例如a = 123之后,是否可以检查哪种类型是联合的?我的方法是将这个联合添加到某个结构中,并在它为int时将uniontype设置为1,当它为double时将其设置为2.
typedef struct somestruct {
int uniontype
myunion numbers;
} mystruct;
Run Code Online (Sandbox Code Playgroud)
有没有更好的解决方案?
我psycopg2在 python (2.7.10) 中使用连接到 postgresql 数据库。文档对动态 SQL 语句的组成非常清楚:
从不,从不,永远不要使用 Python 字符串连接 (+) 或字符串参数插值 (%) 将变量传递给 SQL 查询字符串。甚至不是在枪口下。
在psycopg22.7 版中,有一个新sql模块可以安全地防止 SQL 注入来执行此字符串组合。尽管如此,我还是不明白如何正确构建如下语句:
import psycopg2 as ps
C = psycopg.connect(host='my_host', port=Port, database='My_DB')
cur = C.cursor()
schema = 'some_schema'
table = 'some_table'
SQL = cur.execute("SELECT * FROM "+schema+"."+table+";") # This is horribly wrong
SQL = cur.execute("SELECT * FROM some_schema.some_table;") # That's what the result should be
Run Code Online (Sandbox Code Playgroud) 我的前端代码:
<form action="" onSubmit={this.search}>
<input type="search" ref={(input) => { this.searchInput = input; }}/>
<button type="submit">??</button>
</form>
// search method:
const baseUrl = 'http://localhost:8000/'; // where the Express server runs
search(e) {
e.preventDefault();
let keyword = this.searchInput.value;
if (keyword !== this.state.lastKeyword) {
this.setState({
lastKeyword: keyword
});
fetch(`${baseUrl}search`, {
method: 'POST',
// mode: 'no-cors',
headers: new Headers({
'Content-Type': 'application/json'
}),
// credentials: 'include',
body: JSON.stringify({keyword})
})
}
}
Run Code Online (Sandbox Code Playgroud)
和我的Express.js服务器代码:
app.all('*', (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
res.header('Access-Control-Allow-Headers', …Run Code Online (Sandbox Code Playgroud) 例如,此处的OBR段引用表具有以下标头:
以下是我的观察:
OBR.1,OBR.2,OBR.3等等.0?SI,EI,ST,XCN,ID,NDL,等.以下是我不了解的主要内容:
O,R,RE,C,B,X,W*,1,20065,0074,9999