我有两个桌子。 promote_student
和Student
。我想将数据从promote_student
复制到str = "INSERT INTO [promote_student]
SELECT *
FROM [Student]
WHERE [SrNo] = " & row.Cells("sr_no").Value & "
AND [session] = " & from_session.Text & ""
cmd = New OleDb.OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "promote_student")
。
对于此任务,我编写了以下查询:
sr_no
此处from_session
是唯一值,import * as sinon from 'sinon'
import UserDetails from '../../src/model/UserDetails';
import * as ClassValidator from "class-validator";
import * as PasswordHash from 'password-hash';
let sandbox: sinon.SinonSandbox;
describe('Model > LoginUserDetails', () => {
let userDetailsLetralObject = {
email: 'zia@g.com',
password: 'Savanur1',
roles: ['lecturer'],
departments: ['ec']
};
const userDetails = new UserDetails(userDetailsLetralObject.email,
userDetailsLetralObject.password,
userDetailsLetralObject.roles,
userDetailsLetralObject.departments,
false
);
beforeEach(() => {
sandbox = sinon.createSandbox();
});
afterEach(() => {
sandbox.restore();
});
describe('constructor testing...', () => {
test('With password hash', async (done) => {
const passwordHashStub = sandbox.stub(PasswordHash, 'generate').returns('hashedPassword')
console.log(PasswordHash.generate('mnop'))
// Here it prints string 'hashedPassword' i.e returned buy passwordHashStub method
let userDeatilsObj = await new UserDetails(
userDetailsLetralObject.email,
userDetailsLetralObject.password,
userDetailsLetralObject.roles,
userDetailsLetralObject.departments,
true);
expect(passwordHashStub.withArgs(userDetailsLetralObject.password).calledOnce).toBeTruthy()
// This will check for not equal
expect(userDeatilsObj).not.toEqual(userDetails)
expect(userDeatilsObj.validatePassword('hashedPassword')).toBeTruthy()
done();
});
});
});
是'2018-2019',但是此查询没有复制任何内容。我也没有任何错误。
答案 0 :(得分:0)
在此查询中,如果不是,则您的promote_student表列和Student表列将相同。并且请不要连接您的SQL查询,请使用参数来保护Sql注入。您的查询如下:
public static void main(String[] args) {
// Sample Strings to be subtituted
String y = "/person/PATH_VARIABLE/address/PATH_VARIABLE";
String y1 = "/person/PATH_VARIABLE/PATH_VARIABLE";
// Tried this
//y = y.replaceAll("PATH_VARIABLE", "\\((.*?)\\)");
//y1 = y1.replaceAll("PATH_VARIABLE", "\\((.*?)\\)");
// Tried this one
y = y.replaceAll("PATH_VARIABLE", "(?<=/)(.*?)(?=/?)");
y1 = y1.replaceAll("PATH_VARIABLE", "(?<=/)(.*?)(?=/?)");
// Sample input strings to match
String x = "/person/user.zian/address/123";
String x1 = "/person/nhbb/bhbhb/ghyu";
String x2 = "/person/nhbb/bhbhb";
System.out.println(x.matches(y)); // returns true
System.out.println(x1.matches(y)); // returns false
System.out.println(x1.matches(y1)); // returns true but should return false
System.out.println(x2.matches(y1)); // returns true
}
答案 1 :(得分:0)
如果要插入数据,则应呼叫vd <- merge(d, v, by="ID")
。
我也不相信x <- vd[vd$place == "a",]
hist(x$layer)
是插入数据的最佳方法,尤其是当您有主键时。相反,您要指定要插入的列以及要从中选择的列。
我会强烈考虑使用参数来避免SQL注入。有关更多信息,请参见Bobby Tables。我使用cmd.ExecuteNonQuery()
作为参数的占位符。使用SELECT * FROM [Student]
时,请务必注意,重要的不是参数的名称而是参数的声明顺序。我指定了数据类型,因此请考虑使用OleDbParameter Constructor (String, OleDbType)添加参数。
最后,我还将考虑实施Using:
.NET Framework垃圾收集器(GC)处理托管资源,而无需您进行任何额外的编码。对于托管资源,您不需要使用模块。但是,您仍然可以使用Using块来强制处置托管资源,而不必等待垃圾回收器。
这是一些示例代码:
?
请注意,我不知道您的表结构,因此提供了一个示例。您将不得不更改列名称以适合
还要注意,我已经使用过
OleDbCommand
。您将要用数据库中使用的数据类型替换Using con As OleDbConnection = cn, cmd As New OleDbCommand("INSERT INTO [promote_student] (column1, column2, column3) SELECT column1, column2, column3 FROM [Student] WHERE [SrNo] = ? AND [session] = ?", con) con.Open() cmd.Parameters.Add("@srNo", OleDbType.[Type]).Value = row.Cells("sr_no").Value cmd.Parameters.Add("@session", OleDbType.[Type]).Value = from_session.Text cmd.ExecuteNonQuery() End Using
。