Re: Issues with ADO Queries, and TADOQuery



oCommand.Parameters.CreateParameter usually works for me and contains
everything ADO needs to know - name, datatype, direction, size and value.

Hope this helps.

Nige


<michael.martinek@xxxxxxxxx> wrote in message
news:1181808670.541010.20090@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Working on some queries.. and I've been looking around for about the
last 5 hours now, and I'm not getting anywhere. This is working with
an Access DB.

Here's the code I'm using to try to insert data:


try
oCommand := TADOQuery.Create(nil);
oCommand.Connection := AConnection;

oCommand.SQL.Clear;
oCommand.SQL.BeginUpdate;

sMD5Hash := MD5HashString('test');
oCommand.SQL.Add('INSERT INTO ' + TB_PAGE_ALIASES + ' (page_id,
url_type, url, data_md5, data) VALUES
(:PAGEID, :URLTYPE, :URL, :MDHASH, :THEDATA)');
end;
oCommand.SQL.EndUpdate;

oCommand.Parameters.ParamByName('PAGEID').DataType := ftInteger;
oCommand.Parameters.ParamByName('PAGEID').Value := APageID;

oCommand.Parameters.ParamByName('URLTYPE').DataType := ftInteger;
oCommand.Parameters.ParamByName('URLTYPE').Value := AURLType;


oCommand.Parameters.ParamByName('URL').DataType := ftString;
oCommand.Parameters.ParamByName('URL').Value := '"' +AURL + '"';

oCommand.Parameters.ParamByName('MDHASH').DataType := ftString;
oCommand.Parameters.ParamByName('MDHASH').Value := '"' + sMD5Hash
+ '"';

oCommand.Parameters.ParamByName('THEDATA').DataType := ftBlob;

oCommand.Parameters.ParamByName('THEDATA').LoadFromFile(ACacheFile,
ftBlob);

oCommand.ExecSQL();

Result := CCDB_GetInsertID(AConnection);
finally
FreeAndNil(oCommand);
end;

Before, I was using TADOCommand.. but I couldn't get that working, and
couldn't find anything on the net, Borlands site, or any examples.. so
I tried TADOQuery, and I still get errors about data type mismatches.

Here's the create-table defs I used:

AddColumn(oTable, oCatalog, 'alias_id', adInteger, 0,
['AutoIncrement', true, 'Nullable', false]);
AddColumn(oTable, oCatalog, 'page_id', adInteger, 0, ['Nullable',
false]);
AddColumn(oTable, oCatalog, 'url_type', adUnsignedTinyInt, 0,
['Nullable', false]);
AddColumn(oTable, oCatalog, 'url', adLongVarWChar, 0, ['Nullable',
false]);
AddColumn(oTable, oCatalog, 'data_md5 ', adVarWChar, 32,
['Nullable', true]);
AddColumn(oTable, oCatalog, 'data', adVarBinary, 0, ['Nullable',
true, 'Jet OLEDB:Compressed UNICODE Strings', true]);

I've used so damn many different variations of the insertion that I've
lost count. For example, using Parameters.AddParameter and setting
properties from there... Other insertions work just fine with other
tables, so I'm at a loss of why this one just isn't working. Anyone
able to look and see if I'm doing something obviously wrong? I feel
totally shafted with the lack of information and examples available
from Borland in regards to ADO. It is most certainly not as straight
forward as more common database wrappers that I've seen in other
languages.

Thanks in advance!
Mike



.