E
E
Evgeny Ivanov2019-06-06 10:12:45
SQL
Evgeny Ivanov, 2019-06-06 10:12:45

How to select data using UniDac from DBF?

The question is a little general, since this component has a huge number of settings.
I am writing a program using UniDac and DBF for the first time and I doubt the correctness of my code.
Working code. But there are some questions and problems.

base_path:='C\base\'; //Путь к базе
//sql_request:='SELECT * FROM BASE1 WHERE N="13116"'; //Запрос - находит данные
sql_request:='SELECT * FROM BASE1 WHERE F_NAME="Иван"'; //Запрос - не находит данные, а Иван в F_NAME есть.

UniConnection1.ProviderName := 'DBF';
UniConnection1.Database := base_path;
UniConnection1.SpecificOptions.Values['DBFFormat'] := 'dfFoxPro2';
UniConnection1.SpecificOptions.Values['Direct'] := 'True';
UniConnection1.Connect;

UniQuery1.Connection := UniConnection1;
UniQuery1.SQL.Text :=sql_request;
UniQuery1.Open;


sql_result:=UniQuery1.FieldByName('NAME').AsString; //Получили данные выполнив запрос
records_count:=UniQuery1.RecordCount; //Заодно и узнаем сколько там строк
memo1.Lines.Add(inttostr(records_count)); //Вывели
memo1.Lines.Add(sql_result); //Вывели

UniQuery1.Close;
UniConnection1.Close;

1) SQL query with Russian letters does not work. Works with English. Apparently something needs to be adjusted or converted. What should be done?
2) Do I think correctly that in order to display all the records I need to find out their number (UniQuery1.RecordCount) and iterate over them "shifting" (UniQuery1.Next;)? Usually they do this, but maybe there is another way.
3) Are there obvious bugs in my code? Something didn’t close, something didn’t open, did you set it up? I wrote according to the official manual.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question