Category Archives: Informática e Internet

Fedora Linux 17 64 bit: How to install libraries to compile a c++ CLI program to 32 bit executable

Fedora 17 64 bit: Como instalar librerias para compilar un programa c++ de linea de comando como un ejecutable de 32 bit

In Netbeans, go to Run -> Set project configuration -> Customize -> C++ compiler -> Architecture -> 32 bits

But I was getting this error when trying to compile to a 32 bit executable in my 64 bit Fedora system:

g++ -m32 -c -O2 -MMD -MP -MF build/Release/GNU-Linux-x86/main.o.d -o build/Release/GNU-Linux-x86/main.o main.cpp
In file included from /usr/include/features.h:386:0,
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/x86_64-redhat-linux/32/bits/os_defines.h:40,
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/x86_64-redhat-linux/32/bits/c++config.h:414,
from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/cstdlib:43,
from main.cpp:8:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

Then I found this: http://ask.fedoraproject.org/question/365/how-do-i-install-32bit-libraries-on-a-64-bit

I installed the required packages:

sudo yum install glibc.i686 libgcc.i686 libstdc++.i686 glibc-devel.i686

Thanks to Jim Blandy!

SQL Server 2005 – Create backup script for all user databases

— Create backup script
— MDaponte – 2010-09-15

set nocount on

declare @Dir as varchar(100)
set @Dir = ‘E:\MyBackups’
–print @Dir

declare @DT as varchar(16)
set @DT = replace(replace(replace(convert(char(16), getdate(), 120), ‘-‘, ”), ‘:’, ”), ‘ ‘, ‘_’)
–print @DT

select ‘backup database ‘ + name +
       ‘ to disk = ”’ + @Dir + ‘\’ + name + ‘_db_’ + @DT + ‘.bak” with format ;’
  from master..sysdatabases
 where name not in (‘master’, ‘tempdb’, ‘model’, ‘msdb’, ‘ReportServerTempDB’)
 order by dbid

SQL Server left pad with zeros function

Funcion en SQL Server para ajustar un string a la derecha, llenandolo a la izquierda con ceros.


if object_id ( ‘fnLeftPadWithZeros’, ‘FN’ ) is not null
   drop function fnLeftPadWithZeros
go

create function fnLeftPadWithZeros(@strInput varchar(max), @IntLenght smallint)
   returns varchar(max)

as
begin
   if @strInput is not null
   begin
      if len(@strInput) <= @IntLenght
      begin
         set @strInput = replicate(‘0’, @IntLenght – len(ltrim(rtrim(@strInput)))) +
                         @strInput

      end
   end
   return @strInput
end
go


— PRUEBA DE LA FUNCION
declare @Text varchar(256)
set @Text = ‘1’
select Original = @Text
select SpacesRemoved = dbo.fnLeftPadWithZeros(@Text, 10)
go


List databases and file in SQL Server 2000

set nocount on
declare @db as nvarchar(50)
declare @sql as nvarchar(200)
declare cdb cursor for select name from master..sysdatabases
open cdb
while (1=1)
begin
   fetch cdb into @db
   if @@FETCH_STATUS != 0
      break
   print ‘Database: ‘ + @db
   set @sql = N’select left(name, 30) name,
                       left(filename, 60) filename,
                       (size*8/1024) as MB
                  from ‘ + rtrim(@db) + ‘..sysfiles’
   execute sp_executesql @sql
end
close cdb
deallocate cdb

 

Recorrer una lista de items en SQL Server 2005

Como no existe FOR EACH o algun sucedaneo, tuve que inventar esto…

declare @TipoArch char(3)

declare cTipoArch cursor for
   select ‘NSF’
   union
   select ‘PI’
   union
   select ‘SL’

open cTipoArch
while (1=1)
begin
   fetch cTipoArch into @TipoArch
   if @@FETCH_STATUS != 0
      break

   print @TipoArch

end
close cTipoArch
deallocate cTipoArch


SQL Server – Print a string adjusted to the right

— supongamos que tenemos una variable de 10 posiciones
declare @var varchar(10)

— y tiene un valor corto que queremos imprimir ajustado a la izquierda con ceros…
print ‘Asi esta la variable de paquete…’
set @var = ‘1’
print @var

print ”
print ‘…y asi la vamos a dejar’
print ”
print ‘1234567890’
print ‘———-‘

— este replicate es la solucion
print replicate(‘0’, 10 – len(rtrim(@var))) + @var

 

Asi esta la variable de paquete…
1
 
…y asi la vamos a dejar
 
1234567890
———-
0000000001

 

Como copiar un diagrama de la base de datos en SQL Server 2005

How to copy a database diagram in SQL Server 2005
 
— que diagramas hay en esta base de datos
— show database diagrams in current database
select * from sysdiagrams
 
— copio el diagrama con un nuevo nombre
— copy the diagram with a new name
insert into sysdiagrams (name, principal_id, version, definition)
   select ‘NUEVO DIAGRAMA’, principal_id, version, definition
     from sysdiagrams
    where name = ‘DIAGRAMA’