Two coulmns can not be null at the same time in sql
Suppose there a table called
Employee
ID number, name varchar(24 char), address varchar2(100 char),
alternateAddress(100 char), sex varchar2(10 char)
Now I want to put constraint such that both address and alternateAddress
cannot be null i.e possible cases are:
address is null and alternateAddress is not null
alternateAddress is null and address is not null
alternateAddress is not null and address is not null
But cannot happen that any record in Employee table inserted with
alternateAddress and address both null
Bohaty
Thursday, 3 October 2013
Wednesday, 2 October 2013
String to Integer Mapping
String to Integer Mapping
Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to
26 and then ,AA to 27, AB to 28 and so on BUT BA or cb or cbe or any
string which has letters in descending order should not be numbered a for
eg: BB should be 53 as BA is not numbered .this question is very similar
to Convert A to 1 B to 2 ... Z to 26 and then AA to 27 AB to 28 (column
indexes to column references in Excel) but with a slight difference as
mentioned above
Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to
26 and then ,AA to 27, AB to 28 and so on BUT BA or cb or cbe or any
string which has letters in descending order should not be numbered a for
eg: BB should be 53 as BA is not numbered .this question is very similar
to Convert A to 1 B to 2 ... Z to 26 and then AA to 27 AB to 28 (column
indexes to column references in Excel) but with a slight difference as
mentioned above
Ñ# modPow negative exponent trick
Ñ# modPow negative exponent trick
I try to use using System.Numerics.BigInteger; and perfom modPow with
negative exponent, I read documentation about Exception, that's why I did
some trick
//a^(-x) mod n == (a^(-1))^x mod n
BigInteger tmp = BigInteger.ModPow(BigInteger.Divide(BigInteger.One, a),
secretKey, pCommon);
BigInteger resBigInteger = BigInteger.Multiply(b, tmp);
But tmp is 0. How I can resolve that problem?
I try to use using System.Numerics.BigInteger; and perfom modPow with
negative exponent, I read documentation about Exception, that's why I did
some trick
//a^(-x) mod n == (a^(-1))^x mod n
BigInteger tmp = BigInteger.ModPow(BigInteger.Divide(BigInteger.One, a),
secretKey, pCommon);
BigInteger resBigInteger = BigInteger.Multiply(b, tmp);
But tmp is 0. How I can resolve that problem?
how to sort names and numbers?
how to sort names and numbers?
After completing my school assignment on simple array sorts I came up with
this question. Say I have a textbox with a name in it. Right beside that I
have a textbox with number in it. Exp txtBox1 = "John Doe", txtBox2 = 8.
Lets say I have 10 rows. that would be 20 text boxes. How could I randomly
sort these by name keeping all like numbers together in sequential order.
Output should look something like this. The key here is to randomly sort
the names within the same number group.
John Doe 3
Mary Jane 3
name 4
name 4
name 4
name 5
name 7
name 7
name 8
name 8
After completing my school assignment on simple array sorts I came up with
this question. Say I have a textbox with a name in it. Right beside that I
have a textbox with number in it. Exp txtBox1 = "John Doe", txtBox2 = 8.
Lets say I have 10 rows. that would be 20 text boxes. How could I randomly
sort these by name keeping all like numbers together in sequential order.
Output should look something like this. The key here is to randomly sort
the names within the same number group.
John Doe 3
Mary Jane 3
name 4
name 4
name 4
name 5
name 7
name 7
name 8
name 8
Ampersand encoding in img src
Ampersand encoding in img src
I am trying to display an image (gravatar), but the ampersand in its link
seem to be problematic.
At first, I had:
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>& in url</title>
</head>
<body>
<a
href="http://www.gravatar.com/avatar/f14e8ce12e7d7ffc11fe8a29127030da.jpg?d=mm&r=r">Link
to image</a>
<img
src="http://www.gravatar.com/avatar/f14e8ce12e7d7ffc11fe8a29127030da.jpg?d=mm&r=r"
alt="display image">
</body>
</html>
The link (<a>) works fine this way, but the image (<img>) won't show. And
of course it doesn't pass the w3c validation.
I encoded the ampersand to &, but the result stays the same (except
for the w3c validation which is OK). I even tried a urlencoded version
(via PHP) with no luck.
Any idea on what I am missing?
I am trying to display an image (gravatar), but the ampersand in its link
seem to be problematic.
At first, I had:
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>& in url</title>
</head>
<body>
<a
href="http://www.gravatar.com/avatar/f14e8ce12e7d7ffc11fe8a29127030da.jpg?d=mm&r=r">Link
to image</a>
<img
src="http://www.gravatar.com/avatar/f14e8ce12e7d7ffc11fe8a29127030da.jpg?d=mm&r=r"
alt="display image">
</body>
</html>
The link (<a>) works fine this way, but the image (<img>) won't show. And
of course it doesn't pass the w3c validation.
I encoded the ampersand to &, but the result stays the same (except
for the w3c validation which is OK). I even tried a urlencoded version
(via PHP) with no luck.
Any idea on what I am missing?
Tuesday, 1 October 2013
Setting up a Daemon in Unix
Setting up a Daemon in Unix
I have scheduled a crontab job in AIX 6.1 OS to run twice in an hour which
runs for the whole day to process a load.
The load which crontab kicks off needs files to arrive at a particular
directory and if the files arrive, I process them.
It so happens that for the 24 times the crontab kicks off my load there
would be only 7 times I actually receive the files and for the rest of the
times I receive no files and the load reports saying that no files
received and I cannot preict when files arrive as it can arrive anytime.
I heard that a DAEMON can be setup in Unix which can monitor for files
arriving at a particular destination and call other scripts after that.
I was thinking if it were possible to create a daemon to monitor a
particular destination and if files are present, It can call a shell
script.
Is this possible, if yes how can I code the daemon. I have no prior
experience with daemons. Can anyone clarify.
I have scheduled a crontab job in AIX 6.1 OS to run twice in an hour which
runs for the whole day to process a load.
The load which crontab kicks off needs files to arrive at a particular
directory and if the files arrive, I process them.
It so happens that for the 24 times the crontab kicks off my load there
would be only 7 times I actually receive the files and for the rest of the
times I receive no files and the load reports saying that no files
received and I cannot preict when files arrive as it can arrive anytime.
I heard that a DAEMON can be setup in Unix which can monitor for files
arriving at a particular destination and call other scripts after that.
I was thinking if it were possible to create a daemon to monitor a
particular destination and if files are present, It can call a shell
script.
Is this possible, if yes how can I code the daemon. I have no prior
experience with daemons. Can anyone clarify.
Search a table based on multiple rows in another table
Search a table based on multiple rows in another table
Basically I have three MySQL tables:
Users - contains base information on users
Fields - describes additional fields for said users (e.g. location, dob etc.)
Data - Contains user data described via links to the fields table
With the basic design as follows (the below is a stripped down version)
Users:
ID | username | password | email | registered_date
Fields
ID | name | type
Data:
ID | User_ID | Field_ID | value
what I want to do is search Users by the values for the fields they have,
e.g. example fields might be:
Full Name
Town/City
Postcode
etc.
I've got the following, which works when you're only wanting to search by
one field:
SELECT `users`.`ID`,
`users`.`username`,
`users`.`email`,
`data`.`value`,
`fields`.`name`
FROM `users`,
`fields`,
`data`
WHERE `data`.`Field_ID` = '2'
AND `data`.`value` LIKE 'london'
AND `users`.`ID` = `data`.`User_ID`
AND `data`.`Field_ID` = `fields`.`ID`
GROUP BY `users`.`ID`
But what about if you want to search for Multiple fields? e.g. say I want
to search for Full Name "Joe Bloggs" With Town/City set to "London"? This
is the real sticking point for me.
Is something like this possible with MySQL?
Basically I have three MySQL tables:
Users - contains base information on users
Fields - describes additional fields for said users (e.g. location, dob etc.)
Data - Contains user data described via links to the fields table
With the basic design as follows (the below is a stripped down version)
Users:
ID | username | password | email | registered_date
Fields
ID | name | type
Data:
ID | User_ID | Field_ID | value
what I want to do is search Users by the values for the fields they have,
e.g. example fields might be:
Full Name
Town/City
Postcode
etc.
I've got the following, which works when you're only wanting to search by
one field:
SELECT `users`.`ID`,
`users`.`username`,
`users`.`email`,
`data`.`value`,
`fields`.`name`
FROM `users`,
`fields`,
`data`
WHERE `data`.`Field_ID` = '2'
AND `data`.`value` LIKE 'london'
AND `users`.`ID` = `data`.`User_ID`
AND `data`.`Field_ID` = `fields`.`ID`
GROUP BY `users`.`ID`
But what about if you want to search for Multiple fields? e.g. say I want
to search for Full Name "Joe Bloggs" With Town/City set to "London"? This
is the real sticking point for me.
Is something like this possible with MySQL?
Subscribe to:
Posts (Atom)