Archive

Archive for the ‘windows’ Category

MySQL – Disable Foreign Key Checks or Constraints

March 9, 2009 Gaurav Sohoni 1 comment

Databases are all about saving data. With DBMS and RDBMS, the entire data became relational and all the records became related to each other as in the real world. So came into existence the concepts of primary keys, foreign keys, foreign key constraints and whole bunch of other terms like composite keys, referential integrity, indexes and what not.

So coming back to the objective of pinning down this post, some days ago I came across the requirement of deleting some user records from the user table. As soon as I tried deleting the records, I came across the error of referential integrity where in I was greeted with the error that child records were there and hence the delete operation was not allowed.

So I searched for a shortcut which could let me do my task. And I came across this …


SET foreign_key_checks = 0;
DELETE FROM users where id > 45;
SET foreign_key_checks = 1;

By setting the foreign key check to 0, I was able to update / delete my users table. Once I was done with my operations on the user table, I reset the key check to 1 again and everything is back in place now.

You can always drop a FOREIGN KEY the usual way ..


ALTER TABLE users DROP FOREIGN KEY <foreign_key_name>

As correctly pointed out by tboehm in the comments, I disabled the foreign key checks for some requirement of mine. It is absolutely important to think about the repercussions of this. It is always advisable to start with the child entries and then proceed for the parents. The sole purpose of this article is to make you aware of the option which disables the foreign key constraints.

I guess other available options and arguments for ALTERING TABLES can be found here ..

MySQL ALTER TABLE syntax

Ciao!!!

SVN or Subversion Repository – How would you set it up?

February 26, 2009 Gaurav Sohoni 1 comment

It has been a long time since I posted my last blog post. So here I am ‘populating’ my post with some information that could be of some worth to me and others in need. So without much delay, let me put down the ad hoc article on setting up svn repository. It also talks about creating a structured hierarchy for code management and also gives information on adding projects to SVN repository.

To create svn repository svnadmin command line tool is used.

$ svnadmin /home/gaurav/new_repo

To add directories to the new repository …


$ svn mkdir file:///home/gaurav/new_repo/main_project


$ svn mkdir file:///home/gaurav/new_repo/main_project/branches


$ svn mkdir file:///home/gaurav/new_repo/main_project/tags


$ svn mkdir file:///home/gaurav/new_repo/main_project/trunk


When directories are added, it asks for the commit comments.

Once the repository structure is ready, import the code like this:


$ svn import /home/gaurav/my_new_app/ file:///home/gaurav/new_repo/main_project/trunk

Following command runs svn server @ port 4444 for localhost

-r is for the repository and should be passed the repository path

$ svnserve -d -r /home/gaurav/repository/ --listen-port 4444 --listen-host localhost

Once svn server starts as a daemon, checkout can be done as:

$ svn co svn://localhost:4444/momsworld/trunk mw_0718

—————————————————————————————

Add users to your server

In order to authenticate our intended users, some changes are required to be made. Inside the new repo (c:\svn-repo or /home/gaurav svn-repo), there is a directory called conf. There you will find svnserve.conf.

You need to enable these lines in the file:

[general]
anon-access = read
auth-access = write
password-db = passwd

All other comments can be left untouched. For easy readability, I have only put the required section above.

With this setting, anyone would be able to read the files but only an authenticated user would be able to checkin. Also password-db tells server that a file named ‘passwd’ would be storing usernames and passwords.

Let’s create that file now. It should also be in the conf directory and look like this:

[users]
david = secret

Similarly many users could be added in the format NAME = PASSWORD. There are many other advanced ways to add password protection to Subversion but this one is the easiest I suppose. Subversion has good integration with Apache’s web server authentication so that could be utilized as well.

Before you REinstall windows …

So I was on my desk working when I realized that my mouse had stopped working and I dint have a spare mouse to replace it with. No problem. I had one more option. I pulled out my lappy :) and started it.

As soon as I got logged in, I knew there was something wrong with my laptop. It took me a second to realize that it was infected with some kind of virus. The most annoying part of the entire episode was not being able to work when I was supposed to work on something damn important. On Vista, my explorer kept crashing. It really frustrated me for some time. Playing with it for sometime made me realize that my personal computer was in bad shape.

I scanned my entire system to find only few infections which dint seem to me as potential trouble makers. So I went ahead and tried a newer version of my antivirus.

Downloaded -> Installed -> Scanned -> Cleaned. My lappy was moved from ICU to GENERAL ward. Then I checked some settings and did some tweaks to bring my PC back to life. I started trusting antiviruses again ;)

I could get my PC back in shape :D without formatting my system or reinstalling Vista and hence I could save few hours reinstalling everything

It was then that I thought of writing this post. I just hope that these things will help you avoid atleast few reinstalls / fresh installs.

So before you go for a reinstall / fresh install, try these and see if it comes handy.

1. Make sure you have an antivirus installed. System scan takes time but should be performed sometimes. Your WINDOWS partition should be given preference for scanning.

2. If you come across any weird activity (slow system / popups / explorer related issues), the first place to check should be startup programs. You can see the list by typing “msconfig” in windows run dialog box. If you see entries which you had never installed, disable them and restart to check if that helps. If it does then you need to remove those programs. Uninstall / Delete the installed folder.

3. Try logging in Safe Mode to check if the system remains stable. If it remains stable, try uninstalling recently installed programs. If not, then you might be required to start from scratch, format and reinstall windows.

4. Try running some registry cleaners. Sometimes viruses create links in registry to get executed every time with system startup. Most AV programs take care of this now.

5. Do Ctrl+Alt+Del to check the running programs and system. Kill the unwanted processes. Check for processes that reappear with windows startup but were never installed or meant to be there.

6. Keep your Antivirus updated.

7. Avoid using unscanned pendrives.

8. Keep cleaning/deleting your internet history / cookies.

9. And above all, always keep a backup of your important stuff.

There are many helpful articles on the net that could / would /should help you out on some specific problem.

As long as we have PCs, we have OSs, we will keep getting infected. The problem is not infection though. The issue stays with us. Our ignorance leads to situations that make things move out of our hands.

So go get an antivirus (ur techie friends should be able to help you with it) and be prepared.

To name a few:

Norton Antivirus / McAfee / AVG / Avast / Panda

And DO NOT FORGET … You are NEXT…next to get infected… :D

localhost to myname.com

October 1, 2007 Gaurav Sohoni Leave a comment

Localhost is your machine, and to access some application running on it you use something like http://localhost or localhost:<port>.

Letz say you want your name in the URl that you supply to access the application, then you need to do the following things on Windows:

Goto C:\Windows\System32\drivers\etc and edit the hosts file


# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# 127.0.0.1 localhost

Comment last line and add new one:

127.0.0.1 myname

Now to access your web application, just direct ur browser to http://myname:<port>

I added this info as I myself keep forgetting the hosts file location ;)

Categories: windows Tags: , ,