小编Ste*_*edl的帖子

带 Like + '%' 的 Knex 查询不起作用

我有这个查询,必须选择通过描述过滤的所有书籍,忽略大写/小写。

所以我在 adonis.js / node.js 中进行此查询:

 const queryBook = Book
            .query()
            .with('user')
 queryBook.where('description', 'like', '%'+bookDescription[0]+'%')
Run Code Online (Sandbox Code Playgroud)

我有这样的记录bookDescription

“学生西班牙语版 1 版”

但是当我尝试仅使用小写的“es”进行过滤时,knex 不会返回任何记录。

当我输入“Es”时,将带有我输入的描述的书归还,因此,类似 %es% 不起作用。

我进行了一次调试,发现了这一点:

knex:query select * from "books" where "description" like ? limit ? undefined +7ms
knex:bindings [ '%es%', 10 ] undefined +6ms
Run Code Online (Sandbox Code Playgroud)

显然我没有发现任何错误,但我认为必须like以小写形式返回记录。

我忘记了什么?

node.js knex.js adonis.js

1
推荐指数
1
解决办法
7892
查看次数

为什么不能像 C (a[i] == i[a]) 那样在 swift 中交换数组名称和索引的位置?

C 代码:-

#include <stdio.h>

int main()
{
   int a[5]={33,19,13,25,51};
   int t1 = a[4];
   int t2 = 4[a];         // surprise here
   printf("%d\n", t1);
   printf("%d", t2);
}
Run Code Online (Sandbox Code Playgroud)

打印相同的输出:- 51 51

但是在 swift 中为什么不能更改数组名称及其索引的位置?`

c arrays swift

0
推荐指数
2
解决办法
95
查看次数

使用 Azure Key Vault 的密钥加密和解密文本

我正在尝试使用 Azure Key Vault 中的密钥来加密和解密 Web API 的 cookie。

对于加密过程,我在该类中使用 RSA:

    public class SimpleRSA
    {
        private RSA _rsa;

        public SimpleRSA(RSA rsa)
        {
            _rsa = rsa;
        }

        public string EncryptAsync(string value)
        {
            var byteData = Encoding.Unicode.GetBytes(value);
            var encryptedText = _rsa.Encrypt(byteData, RSAEncryptionPadding.OaepSHA1);
            var encodedText = Convert.ToBase64String(encryptedText);
            return encodedText;
        }


        public string DecryptAsync(string encryptedText)
        {
            var encryptedBytes = Convert.FromBase64String(encryptedText);
            var decryptionResult = _rsa.Decrypt(encryptedBytes, RSAEncryptionPadding.OaepSHA1);
            var decryptedText = Encoding.Unicode.GetString(decryptionResult);
            return decryptedText;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我使用该代码从密钥中获取 RSA:

  public RSA GetRSA(string appId, string appSecret)
        {
            AuthenticationCallback callback …
Run Code Online (Sandbox Code Playgroud)

c# encryption rsa azure azure-keyvault

0
推荐指数
2
解决办法
9041
查看次数

c 中的多行宏 (#if-#endif)

我的代码:

#define DEBUG 3
#define TEST(...) 
    #if (DEBUG == 3) \
        printf("%s: %s\n", __FILE__, __VA_ARGS__); 
    #endif 

int main(void) {

    TEST("TEST")

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:在标记“printf”之前缺少二元运算符。

我不明白有什么问题

c macros multiline

0
推荐指数
1
解决办法
59
查看次数

使用(空格)输入字符串

我使用 Windows 10 机器和代码块作为 IDE。在代码中,我看到使用空格字符(空格)来输入字符串,例如

scanf(" %[^\n]", s);
Run Code Online (Sandbox Code Playgroud)

这背后的原因是什么?

#include<stdio.h>
#include<string.h>

int main()
{
    int t, i, j, temp, len;
    char s[1002];

    scanf("%d", &t);

    while(t--){
        scanf(" %[^\n]", s);
        len = strlen(s);
        for(i = 0, j = (len-1); i < (len/2); i++, j--){
            temp = s[i];
            s[i] = s[j];
            s[j] = temp;
        }

        printf("%s\n", s);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在这个程序中,程序员只是试图替换字符串的组成部分

c string input

0
推荐指数
1
解决办法
74
查看次数

如何从 IP 地址字符串中获取 4 个整数?

我正在尝试从 IP 地址获取 4 个整数。例如,12.34.56.78。A = 12,b = 34,c = 56,d = 78。这是我的代码:

#include <stdio.h>
#include <stdlib.h>
        
int main()
{
    char ADDRESS[100];
        
    printf("Enter IP: ");
    scanf("%s", ADDRESS);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?

c

0
推荐指数
1
解决办法
57
查看次数

const a = express() 到底是如何工作的?

我最近开始学习 Node/express。有一个疑问困扰了我好几个星期。我知道这是怎么回事,而且我已经能够克服它了。但我无法理解该行中使用的逻辑const a = express()

express = require('express');
const a = express()
Run Code Online (Sandbox Code Playgroud)

我想我以前没有在 javascript 中见过这个。在这种情况下,express是对象还是函数(函数在 JavaScript 中也是对象)对吗?这行代码使变量a能够访问许多重要的方法,例如listen()get()。但这里的语法是不是有问题?要使用该express()函数,我们需要这样写

const express = require('express');
const a = express.express()
Run Code Online (Sandbox Code Playgroud)

或者我们需要使用对象解构来写

const {express} = require('express');
const a = express()
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

0
推荐指数
1
解决办法
548
查看次数

sprintf_s 和访问冲突

我一直在使用 C/C++ 程序在 Windows 上的 Visual Studio 中收到“0xC0000005:访问冲突读取位置错误”,并试图简化以说明我的问题。下面的代码运行得很好:

char tmp[1000];
ULONG64 val1 = 1;
sprintf_s(tmp, 1000, "%lu, %s, %s", val1, "true", "false");
Run Code Online (Sandbox Code Playgroud)

但是,当我向格式中添加额外的 unsigned long 时,会出现访问冲突,如下面的代码所示:

char tmp[1000];
ULONG64 val1 = 1;
ULONG64 val2 = 2;
sprintf_s(tmp, 1000, "%lu, %lu, %s, %s", val1, val2, "true", "false");
Run Code Online (Sandbox Code Playgroud)

c windows visual-c++

-2
推荐指数
1
解决办法
122
查看次数