QODBCResult::exec:无法执行语句:“[Microsoft][ODBC SQL 服务器驱动程序]COUNT 字段不正确或语法错误
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error
当我尝试使用 QODBC 在 QT 中调用存储过程时出现此错误:
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL
Server Driver]COUNT field incorrect or syntax error
参数数量正确,语法对我来说没问题。该过程在 Management Studio 中执行良好。可能是什么问题?
QSqlQuery query(db1);
query.exec("SELECT * from Teachers"); //test query
TableWidget *table = ui->tableWidget;
for (int i = 0; i < table->rowCount(); i++)
{
QComboBox *combo = static_cast<QComboBox*>(table->cellWidget(i,0));
qDebug() << query.prepare("{CALL add_syllabus_line (?,?,?,?,?,?,?,?,?)}");
query.bindValue("teacher_name", teacherName);
query.bindValue("subject_name", "????");
query.bindValue("temporary_name", ratingName);
query.bindValue("type_name", combo->currentText());
query.bindValue("activity_name", table->item(i, 1)->text());
query.bindValue("min_score", table->item(i, 2)->text().toInt());
if (propertiesInstance.fixed) query.bindValue("max_score", 0);
else query.bindValue("max_score", table->item(i, 3)->text().toInt());
query.bindValue("max_score_exists", propertiesInstance.fixed);
query.bindValue("evaluation_by_exam", propertiesInstance.exam);
if (!query.exec())
{
qDebug() << query.lastError();
}
}
程序:
ALTER PROCEDURE [dbo].[add_syllabus_line]
@teacher_name NVARCHAR(50),
@subject_name NVARCHAR(50),
@temporary_name NVARCHAR(50),
@type_name NVARCHAR(50),
@activity_name NVARCHAR(50),
@min_score int,
@max_score int,
@max_score_exists bit,
@evaluation_by_exam bit
AS
BEGIN
SET NOCOUNT ON;
DECLARE @teacher_id int;
DECLARE @subject_id int;
DECLARE @type_id int;
SELECT @teacher_id = Teacher_id FROM Teachers WHERE Teacher_name = @teacher_name;
SELECT @type_id = Activity_type_id FROM Activity_types WHERE Activity_type_name = @type_name;
SELECT @subject_id = subject_id FROM Subjects WHERE Subject_name = @subject_name;
INSERT INTO Syllabi (Teacher_id,
Subject_id,
Temporary_name,
Activity_type_id,
Activity_title,
Activity_min_score,
Activity_max_score,
Max_score_exists,
Evaluation_by_exam) VALUES (@teacher_id,
@subject_id,
@temporary_name,
@type_id,
@activity_name,
@min_score,
@max_score,
@max_score_exists,
@evaluation_by_exam);
END
query.prepare
returns 正确。
我 运行 一个探查器跟踪,查询甚至没有显示在那里,只有测试一个。
select 504,c.name,c.description,c.definition from
master.dbo.syscharsets c where c.id = convert(tinyint,
databasepropertyex ( db_name() , 'sqlcharset')) go
exec sp_datatype_info 11 go
SET QUOTED_IDENTIFIER ON
go
declare @p1 int
set @p1=180150003
declare @p3 int
set @p3=8
declare @p4 int
set @p4=1
declare @p5 int
set @p5=3
exec sp_cursoropen @p1
output,N'SELECT * from Teachers',@p3 output,@p4 output,@p5 output
select @p1, @p3, @p4, @p5
exec sp_cursorclose 180150003 go
除了使用探查器跟踪或扩展事件、DBCC INPUTBUFFER 等确保将准确的语法传递给 SQL 服务器外,插入的 table 是否有任何可能干扰的触发器?
原来是语法的问题,我改成了
query.prepare("{CALL add_syllabus_line (:teacher_name, :subject_name,
:temporary_name, :type_name, :activity_name, :min_score, :max_score, :max_score_exists,
:evaluation_by_exam)}");
QComboBox *combo = static_cast<QComboBox*>(table->cellWidget(i,0));
query.bindValue(":teacher_name", teacherName);
query.bindValue(":subject_name", "Физика");
query.bindValue(":temporary_name", ratingName);
query.bindValue(":type_name", combo->currentText());
query.bindValue(":activity_name", table->item(i, 1)->text());
query.bindValue(":min_score", table->item(i, 2)->text().toInt());
query.bindValue(":max_score", 0);
query.bindValue(":max_score_exists", propertiesInstance.fixed);
query.bindValue(":evaluation_by_exam", propertiesInstance.exam);
qDebug() << query.exec();
qDebug() << query.lastError();
现在可以正常使用了。
当我尝试使用 QODBC 在 QT 中调用存储过程时出现此错误:
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error
参数数量正确,语法对我来说没问题。该过程在 Management Studio 中执行良好。可能是什么问题?
QSqlQuery query(db1);
query.exec("SELECT * from Teachers"); //test query
TableWidget *table = ui->tableWidget;
for (int i = 0; i < table->rowCount(); i++)
{
QComboBox *combo = static_cast<QComboBox*>(table->cellWidget(i,0));
qDebug() << query.prepare("{CALL add_syllabus_line (?,?,?,?,?,?,?,?,?)}");
query.bindValue("teacher_name", teacherName);
query.bindValue("subject_name", "????");
query.bindValue("temporary_name", ratingName);
query.bindValue("type_name", combo->currentText());
query.bindValue("activity_name", table->item(i, 1)->text());
query.bindValue("min_score", table->item(i, 2)->text().toInt());
if (propertiesInstance.fixed) query.bindValue("max_score", 0);
else query.bindValue("max_score", table->item(i, 3)->text().toInt());
query.bindValue("max_score_exists", propertiesInstance.fixed);
query.bindValue("evaluation_by_exam", propertiesInstance.exam);
if (!query.exec())
{
qDebug() << query.lastError();
}
}
程序:
ALTER PROCEDURE [dbo].[add_syllabus_line]
@teacher_name NVARCHAR(50),
@subject_name NVARCHAR(50),
@temporary_name NVARCHAR(50),
@type_name NVARCHAR(50),
@activity_name NVARCHAR(50),
@min_score int,
@max_score int,
@max_score_exists bit,
@evaluation_by_exam bit
AS
BEGIN
SET NOCOUNT ON;
DECLARE @teacher_id int;
DECLARE @subject_id int;
DECLARE @type_id int;
SELECT @teacher_id = Teacher_id FROM Teachers WHERE Teacher_name = @teacher_name;
SELECT @type_id = Activity_type_id FROM Activity_types WHERE Activity_type_name = @type_name;
SELECT @subject_id = subject_id FROM Subjects WHERE Subject_name = @subject_name;
INSERT INTO Syllabi (Teacher_id,
Subject_id,
Temporary_name,
Activity_type_id,
Activity_title,
Activity_min_score,
Activity_max_score,
Max_score_exists,
Evaluation_by_exam) VALUES (@teacher_id,
@subject_id,
@temporary_name,
@type_id,
@activity_name,
@min_score,
@max_score,
@max_score_exists,
@evaluation_by_exam);
END
query.prepare
returns 正确。
我 运行 一个探查器跟踪,查询甚至没有显示在那里,只有测试一个。
select 504,c.name,c.description,c.definition from master.dbo.syscharsets c where c.id = convert(tinyint, databasepropertyex ( db_name() , 'sqlcharset')) go
exec sp_datatype_info 11 go
SET QUOTED_IDENTIFIER ON go
declare @p1 int set @p1=180150003
declare @p3 int
set @p3=8 declare @p4 int set @p4=1 declare @p5 int set @p5=3 exec sp_cursoropen @p1 output,N'SELECT * from Teachers',@p3 output,@p4 output,@p5 output select @p1, @p3, @p4, @p5exec sp_cursorclose 180150003 go
除了使用探查器跟踪或扩展事件、DBCC INPUTBUFFER 等确保将准确的语法传递给 SQL 服务器外,插入的 table 是否有任何可能干扰的触发器?
原来是语法的问题,我改成了
query.prepare("{CALL add_syllabus_line (:teacher_name, :subject_name,
:temporary_name, :type_name, :activity_name, :min_score, :max_score, :max_score_exists,
:evaluation_by_exam)}");
QComboBox *combo = static_cast<QComboBox*>(table->cellWidget(i,0));
query.bindValue(":teacher_name", teacherName);
query.bindValue(":subject_name", "Физика");
query.bindValue(":temporary_name", ratingName);
query.bindValue(":type_name", combo->currentText());
query.bindValue(":activity_name", table->item(i, 1)->text());
query.bindValue(":min_score", table->item(i, 2)->text().toInt());
query.bindValue(":max_score", 0);
query.bindValue(":max_score_exists", propertiesInstance.fixed);
query.bindValue(":evaluation_by_exam", propertiesInstance.exam);
qDebug() << query.exec();
qDebug() << query.lastError();
现在可以正常使用了。