Forum > Databases

[SOLVED] get the data type for a specific variable from the loaded database.

<< < (2/3) > >>

eldonfsr:
I don't know id looking for something like this on dbgrid fiedl.datatype porperity  you can apply this direclty to datasource


procedure TFormMas90.DBGTabKeyPress(Sender: TObject; var Key: char);
Var ColName:String;
    ldate:Tdate;
begin
  Colname:= DbGTab.Columns.Items[DbGTab.SelectedIndex].FieldName;
  with DbgTab  do begin
   if( (Key >=#40) and( Key<=#125)) then begin
     search+=key;
     if(DbGTab.Columns.Items[DbGTab.SelectedIndex].Field.DataType<> ftDate) then begin;
         DBgTab.DataSource.DataSet.Locate(ColName, search,[loCaseInsensitive, loPartialKey]);
         StatusBar1.Panels[0].Text:='Buscando: '+search;
     end else begin
         lDate:=SearchDate(search, Key );
         DBgTab.DataSource.DataSet.Locate(ColName, ldate,[]);
        StatusBar1.Panels[0].Text:='Buscando: '+DateToStr(ldate);
     end;
     key:=#0;
   end;
   if( Key=#27) then begin
     search:='';
     nYY:=Yearof(Now);nMM:=Monthof(Now);nDD:=Dayof(Now);
   end;

  end;
end;           

Zvoni:
Could you explain what you mean with "variable"????
There are DBMS that support "variables", but i'm not sure that's what you mean.

Do you mean "Datatype of a specific Field"?
If yes, cdbc gave you the answer.

Pretty much every modern DBMS has metadata you can query.
So the next question: Which DBMS? MySQL, SQlite or what?

Seenkao:
Благодарю всех за информацию!

Воспользовался возможностями самих СУБД.

Google translate:
Thanks to everyone for the information!

I used the capabilities of the DBMS itself.


SQLite:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SQLQuery.Close;SQLQuery.SQL.Text := 'PRAGMA table_info(myTable)';SQLQuery.Open;while not SQLQuery.EOF dobegin  writeln('Table name - ', SQLQuery.FieldByName('name').AsAnsiString, ' table type ', SQLQuery.FieldByName('type').AsAnsiString);  SQLQuery.Next;end; Other:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SQLQuery.SQL.Text := 'SHOW COLUMNS FROM myFirstDB.firstTable';SQLQuery.DataBase := myDB; SQLQuery.Open;...

Zvoni, я спрашивал как это можно сделать. )))

Zvoni, I asked how this can be done. )))

Zvoni:

--- Quote from: Seenkao on August 05, 2024, 12:44:01 pm ---Thanks to everyone for the information!

I used the capabilities of the DBMS itself.


SQLite:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SQLQuery.Close;SQLQuery.SQL.Text := 'PRAGMA table_info(myTable)';SQLQuery.Open;while not SQLQuery.EOF dobegin  writeln('Table name - ', SQLQuery.FieldByName('name').AsAnsiString, ' table type ', SQLQuery.FieldByName('type').AsAnsiString);  SQLQuery.Next;end; Zvoni, I asked how this can be done. )))

--- End quote ---

err.....to avoid confusion for anyone else finding this:
the usage of "table" in the writeln above (Line 6) is misleading.
It's "Column"

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SQLQuery.Close;SQLQuery.SQL.Text := 'PRAGMA table_info(myTable)';SQLQuery.Open;while not SQLQuery.EOF dobegin  writeln('Column name - ', SQLQuery.FieldByName('name').AsAnsiString, ' Column type ', SQLQuery.FieldByName('type').AsAnsiString);  SQLQuery.Next;end; 

Seenkao:
Да, вы правы. В данном случае я делал для себя в первую очередь. И учту ваши правки!

Google translate:
Yes, you are right. In this case, I did it for myself first and foremost. And I will take your edits into account!  ;)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version