Page 1 of 1

[Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Sun 16 Mar 2014 11:52
by oz8hp
I am trying to insert text (the content of a mail) to a memo field in MS Access but I get a [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

I simply can't identify other problems than the text might be to to - what is the limit in UniDAC?

The code:
procedure TfrmTest.Button1Click(Sender: TObject);
var
Query: TUniQuery;
begin
Query := frmUniConn.CreateQuery;
try
Query.SQL.Clear;
Query.SQL.Add('INSERT INTO tbllogbook');
Query.SQL.Add(' ( ');
Query.SQL.Add(' fldlog_guid');
Query.SQL.Add(' ,fldlog_text');
Query.SQL.Add(' ) values ( ');
Query.SQL.Add(' :fldlog_guid');
Query.SQL.Add(' ,:fldlog_text');
Query.SQL.Add(' ) ');
Query.ParamByName('fldlog_guid').AsString := GuidCreate;
Query.ParamByName('fldlog_text').AsString := Memo1.Text;
Query.Execute;
finally
Query.Free;
end;
end;

frmUniConn is a datamodule where I create the connection to database and the Query

Re: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Mon 17 Mar 2014 18:42
by oz8hp
Figured that one out - had to change code to

procedure TfrmTest.Button1Click(Sender: TObject);
var
Query: TUniQuery;
Stream: TStringStream;
begin
Stream := TStringStream.Create('');
Query := frmUniConn.CreateQuery;
Stream.WriteString(Memo1.Text);
try
Query.SQL.Clear;
Query.SQL.Add('INSERT INTO tbllogbook');
Query.SQL.Add(' ( ');
Query.SQL.Add(' fldlog_guid');
Query.SQL.Add(' ,fldlog_text');
Query.SQL.Add(' ) values ( ');
Query.SQL.Add(' :fldlog_guid');
Query.SQL.Add(' ,:fldlog_text');
Query.SQL.Add(' ) ');
Query.ParamByName('fldlog_guid').AsString := GuidCreate;
Query.ParamByName('fldlog_text').LoadFromStream(Stream, ftMemo);
Query.Execute;
finally
Query.Free;
Stream.Free;
end;
end;

Now I just need testing on MySQL, MS SQL and SQLite :D

Re: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Wed 19 Mar 2014 15:54
by AlexP
Hello,


We cannot reproduce the problem on the latest UniDAC 5.2.7 version and MS Access 2013: data is inserted correctly, please try to reproduce the problem on the latest UniDAC version and let us know the result.

Re: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Wed 19 Mar 2014 18:48
by oz8hp
The problem only exists if the text is > 255 chars

I have no access to the new versions of UniDAC. The program I am altering is an old one I made for a company I used to work for. I am working on their computer with the old Delphi & UniDAC that hasn't been updated for quite some time.

But the solution I have described solves the issue for me with texts > 255 chars

Re: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Thu 20 Mar 2014 13:05
by AlexP
To solve the problem, you should specify explicitly the parameter type, .i.e:

Code: Select all

....
Query.ParamByName('fldlog_text').DataType := ftMemo;
Query.ParamByName('fldlog_text').AsString := Memo1.Text;
....

Re: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

Posted: Thu 20 Mar 2014 14:57
by oz8hp
OK - I will try that.

TNX