Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 09-12-2010
cmfab cmfab is offline
Miembro
 
Registrado: jun 2010
Posts: 419
Poder: 14
cmfab Va por buen camino
Campo Booleano en MySQL

Alguien me puede indicar como se define un campo Booleano en MySQL, osea cual es su simbolo o descripcion en la estructura de la BD y que informacion guarda True o False ó 0 y 1. como poder usar checkboxes en una rejilla de datos para representarlo. Desde ya gracias
Responder Con Cita
  #2  
Antiguo 10-12-2010
rhino0nt rhino0nt is offline
Miembro
 
Registrado: jun 2008
Posts: 25
Poder: 0
rhino0nt Va por buen camino
Caompo boolean en MySQL

Otra razón para utilizar PostgreSQL.

Tipos
BOOL, BOOLEAN

Este tipo no existe en MySQL (al menos no hasta la versión 5.5) en si son una representación para TINYINT(1). Un 0 es considerado Falso y cualquier otro valor es considerado TRUE.

Una forma de emular un tipo boolean es con ENUM('False', 'True') esto te permite utilizar ambas cadenas en tus sentencias SQL, y MySQL almacenará el campo internamente como integer donde False = 0 y True = 1 basándose en el orden en que están especificadas con ENUM.

Espero que esto te sea de utilidad.
Responder Con Cita
  #3  
Antiguo 10-12-2010
cecam cecam is offline
Miembro
 
Registrado: may 2006
Ubicación: Girona
Posts: 47
Poder: 0
cecam Va por buen camino
Como bien comenta rhino0nt en la bdd se define como TINYINT(1).

Después en el Delphi, usamos Zeos, y en la unit ZAbstractRODataset tengo una pequeña modificación en la siguiente función:
Código:
procedure TZAbstractRODataset.InternalInitFieldDefs;
var
  I, J, Size: Integer;
  AutoInit: Boolean;
  FieldType: TFieldType;
  ResultSet: IZResultSet;
  FieldName: string;
  FName: string;
begin
  FieldDefs.Clear;
  ResultSet := Self.ResultSet;
  AutoInit := ResultSet = nil;

  try
    { Opens an internal result set if query is closed. }
    if AutoInit then
    begin
      CheckSQLQuery;
      CheckConnected;
      ResultSet := CreateResultSet(FSQL.Statements[0].SQL, 0);
    end;
    if not Assigned(ResultSet) then
      raise Exception.Create(SCanNotOpenResultSet);

    { Reads metadata from resultset. }

    with ResultSet.GetMetadata do
    begin
      if GetColumnCount > 0 then for I := 1 to GetColumnCount do
      begin
        FieldType := ConvertDbcToDatasetType(GetColumnType(I));

        if FieldType in [ftString, ftWidestring, ftBytes] then
          Size := GetPrecision(I)
        else Size := 0;

        //TinyInt(1)= SmallInt = Boolean
        if  (   (FieldType=ftSmallInt)
             or (FieldType=ftInteger)
             or (FieldType=ftLargeint)
            )
        and (GetPrecision(I)=1)
        then FieldType:=ftBoolean;
        //TinyInt(1)= SmallInt = Boolean

        J := 0;
        FieldName := GetColumnLabel(I);
        FName := FieldName;
        while FieldDefs.IndexOf(FName) >= 0 do
        begin
          Inc(J);
          FName := Format('%s_%d', [FieldName, J]);
        end;

        with TFieldDef.Create(FieldDefs, FName, FieldType,
          Size, False, I) do
        begin
          {$IFNDEF FPC}
{$IFNDEF FOSNOMETA}
          Required := IsWritable(I) and (IsNullable(I) = ntNoNulls);
{$ENDIF}
          {$ENDIF}
{$IFNDEF FOSNOMETA}
          if IsReadOnly(I) then Attributes := Attributes + [faReadonly];
          Precision := GetPrecision(I);
{$ENDIF}
          DisplayName := FName;
        end;
      end;
    end;

  finally
    { Closes localy opened resultset. }
    if AutoInit then
    begin
      if ResultSet <> nil then
      begin
        ResultSet.Close;
        ResultSet := nil;
      end;
      if Statement <> nil then
      begin
        Statement.Close;
        Statement := nil;
      end;
    end;
  end;
end;
Recompilamos las Zeos, y ya podemos usar los Tinyint(1) como si fueran ftBoolean, incluso en diseño.

Saludos!!
Responder Con Cita
  #4  
Antiguo 10-12-2010
cmfab cmfab is offline
Miembro
 
Registrado: jun 2010
Posts: 419
Poder: 14
cmfab Va por buen camino
Muchas gracias a ambos, me sirve de gran utilidad. disculpen por mis agradecimientos tardíos pero no estaba en el trabajo. gracias. un saludo
Responder Con Cita
  #5  
Antiguo 11-12-2010
Avatar de rgstuamigo
rgstuamigo rgstuamigo is offline
Miembro
 
Registrado: jul 2008
Ubicación: Santa Cruz de la Sierra-Bolivia
Posts: 1.646
Poder: 17
rgstuamigo Va por buen camino
Arrow

Algunas referencias al respecto>
http://dev.mysql.com/doc/refman/5.0/...an-values.html
http://dev.mysql.com/doc/refman/5.0/...umn-types.html
http://www.conclase.net/mysql/curso/...ap=005#005_BIT
Saludos...
__________________
"Pedid, y se os dará; buscad, y hallaréis; llamad, y se os abrirá." Mt.7:7
Responder Con Cita
  #6  
Antiguo 29-12-2010
adrall adrall is offline
Miembro
 
Registrado: ene 2007
Posts: 94
Poder: 18
adrall Va por buen camino
Puedes usar el tipo BIT que solo admite CEROS i UNOS.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
convertir booleano a int o de int a booleano jacobobo Conexión con bases de datos 3 05-12-2012 15:24:45
Booleano con Interbase y Delphi 7 Cecilio Conexión con bases de datos 1 26-10-2008 20:38:03
filtrar por campo booleano ale_metall Varios 4 03-10-2008 22:52:28
Ordenar un campo Booleano en MySQL Brewster MySQL 3 24-01-2005 10:52:38
¿Tipo Booleano en SQL Server? noegarcia MS SQL Server 1 22-04-2004 13:50:57


La franja horaria es GMT +2. Ahora son las 15:22:24.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi