[SQL] Count results from stored procedure (without return)

It’s been a while since I haven’t used SQL. Now that I’m using it on a daily basis at work, I may write a little more about SQL than before. So here is an article the aim of which is to show how to find the number of results returned by a stored procedure. It’s in fact a problem which can be easily solved.

So let’s say we have a table containing animals names. Nothing fancy, just something like this:

name
----
Cat
Dog
Rabbit

That’s it for the table. Now we need a stored procedure, so let’s assume we have one : findNameLike which take letters as parameter and returns animals names beginning with these letters.

EXEC findNameLike @beginWith = N'C'

Cat.
Yes, the above call will return Cat.

So, if we want to know how much results were found, we will just write the following code:

DECLARE @numberOfMatch INT
EXEC findNameLike @beginWith = N'C'
SELECT @numberOfMatch = @@ROWCOUNT

The number of results is now available in variable numberOfMatch.

That’s it.
But maybe you also don’t want the stored procedure to return results when you call it. So we need to modify our code a little so that results will be stored in a temporary table and thus not returned, but rather stored in the table.

DECLARE @numberOfMatch INT
DECLARE @tmpTable TABLE (
    name VARCHAR(25)
)

INSERT INTO @tmpTable 
EXEC findNameLike @beginWith = N'C'
SELECT @numberOfMatch = @@ROWCOUNT

I think we’re done here. In a few lines, we’re able to count the results from a stored procedure as well as suppressing its return.

Proxy

Lorsqu’on travaille derrière un proxy, on se retrouve vite à devoir configurer nos outils pour être certain que leur trafic passera bien par celui-ci. Voici donc quelques paramètres de configuration pour répondre à ce problème.

GNU/Linux

Les variables d’environnement qui nous intéresse sont les suivantes:

  • http_proxy
  • https_proxy
  • ftp_proxy
  • no_proxy

On peut également les retrouver en majuscule: HTTP_PROXY par exemple.

La configuration s’effectue de la manière suivante dans un terminal:

export http_proxy=http://yourproxyaddress:proxyport
export no_proxy='127.0.0.1, *.local'

Pour visualiser le contenu d’une variable:

echo $http_proxy

GNOME

gsettings set org.gnome.system.proxy ignore-hosts "['127.0.0.1','*.local' ]"

APT-GET/APTITUDE

Si aptitude n’utilise pas le proxy défini au niveau système pour une raison ou une autre, on peut modifier le fichier /etc/apt/apt.conf pour y ajouter la ligne suivante:

Acquire::http::Proxy "http://yourproxyaddress:proxyport";

GIT

git config --global http.proxy http://yourproxyadress:port
git config --global https.proxy http://yourproxyaddress:port

Si le proxy bloque le protocole git://, on force l’utilisation de http:// :

git config --global url."http://".insteadOf git://

Et en cas de problème avec le protocole https://, on peut envisager :

git config --global http.sslVerify false

WINDOWS

NPM

Dans le fichier .npmrc, ajouter les lignes:

proxy=http://yourproxyadress:port
strict-ssl = false

BOWER

Dans le fichier .bowerrc, ajouter les lignes:

{
  "proxy":"http://yourproxyadress:port",
  "https-proxy":"http://yourproxyadress:port"
}

[Xorg] no screens found

During my previous installation of Arch Linux, I encountered the « error no screens found » when trying to launch X graphic server. It took me a couple hours to understand that my motherboard had « embedded graphic functionality ». So in order to solve my problem, I had to deactivate Intel pilot from the motherboard in the BIOS, so that the system would use the graphic card instead. So an easy solution in my case, but it seems that this error can be obtained in a wide variety of case. If you’re reading this having a similar problem, I hope you’ll find a solution.

Useful command to see graphic cards detected by the system:

lspci | grep VGA

Optimisation et SSD sous GNU/Linux

Depuis quelques mois, je dispose d’un SSD d’une centaine de giga sur lequel se trouve mes partitions systèmes. Le gain de performance est évidemment très appréciable. Mon Arch Linux démarre en quelques secondes; revenir en arrière serait bien difficile. Afin d’améliorer la durée de vie du SSD, intéressons-nous donc aux paramètres de configuration disponible.

Dans le fichier /etc/fstab, nous allons ajouter différents paramètres sur la partition ext4 située sur le SSD.

On ajoute en premier lieu, l’option noatime, permettant de ne pas écrire la date du dernier accès à un fichier si celui-ci n’a pas été modifié lors de cet accès. Ce qui nous donne:

UUID=865bc945-8437-25c6-df1b-ac3fe08bf901 / ext4 rw,noatime 0 1

Le second paramètre consiste à activer l’utilisation de la technologie TRIM. Cette technologie consiste à indiquer au SSD quels blocs de données ne sont plus utilisés et peuvent donc être effacés, améliorant ainsi les performances d’accès au disque. Pour l’utiliser, même démarche que précédemment mais en ajoutant cette fois l’option discard, ce qui nous donne:

UUID=865bc945-8437-25c6-df1b-ac3fe08bf901 / ext4 rw,noatime,discard 0 1

Avant d’activer l’option, il est bon de vérifier que notre SSD supporte cette technologie avec la commande:

# hdparm -I /dev/sda | grep TRIM
        *    Data Set Management TRIM supported (limit 1 block)
        *    Deterministic read data after TRIM

Pour plus d’informations sur le sujet, on pourra regarder du côté du wiki Arch Linux.

Vider le cache de pacman

En premier lieu, on utilise :

paccache -r

Cette commande a pour effet de supprimer toutes les versions d’un paquet, sauf la plus récente. Néanmoins, les paquets désinstallés resteront dans le cache, pour s’en débarrasser, on exécute donc:

paccache -ruk0

Toutes les versions des paquets désinstallés seront ainsi supprimées.

D’après pacman – ArchWiki.