function TMysqlClient.query(
const bquery:
string;
const Args:
array of const;
StoreResult: boolean;
var ExecutedOk: boolean): TMysqlResult;
var
i, j,
iRc: Integer;
aquery : AnsiString;
sLen : Cardinal;
sDummy :
String;
fVar : Double;
begin
// Bind Param
aquery := ansistring(bquery);
fstmt := mysql_stmt_init(fHandle);
if fstmt <>
nil then
begin
iRc := mysql_stmt_prepare(fstmt, @aquery[1], Length(aquery));
if iRc = 0
then
begin
ShowMessage(IntToStr(mysql_stmt_param_count(fstmt)));
SetLength(fbinding, length(Args));
for i := 0
to length(Args) - 1
do
begin
fbinding[i].is_null := 0;
fbinding[i].length := 0;
case Args[i].VType
of
vtInteger:
begin
fbinding[i].buffer_type := MYSQL_TYPE_LONG;
fbinding[i].buffer := @Args[i];
end;
vtString, vtAnsiString, vtUnicodeString:
begin
fbinding[i].buffer_type := MYSQL_TYPE_STRING;
sDummy :=
String(Args[i].VUnicodeString);
sLen := Length(sDummy);
fbinding[i].buffer_length := sLen;
fbinding[i].buffer := Pointer(sDummy);
fbinding[i].length := @sLen;
end;
vtExtended:
begin
fbinding[i].buffer_type := MYSQL_TYPE_DOUBLE;
sLen := sizeof(Double);
fVar := Args[i].VExtended^;
fbinding[i].buffer_length := sLen;
fbinding[i].buffer := @fVar;
fbinding[i].length := @sLen;
end;
end;
end;
if (
not mysql_stmt_bind_param(fstmt, fbinding))
then
begin
if mysql_stmt_execute(fstmt) = 0
then
begin
ShowMessage(IntToStr(mysql_stmt_affected_rows(fstmt)));
end;
end;
end
else
ShowMessage(mysql_stmt_error(fstmt));
end;
end;