The scenario:
I'm creating a login form for an MVC2 application.
How i'm doing it:
The form submits to an MVC2 action which validates the username/password. If it fails validation the action returns the form (a partial view) for the user to try again. If it passes validation the action returns the page the user was visiting before they logged in (a view).
What i want to happen:
1 - when the form is submitted and the user validates successfully, The returned result should replace the current page (like what happens if you don't set an UpdateTargetId).
2 - When the form is submitted and the user fails validation, the returned result should replace the form (like what happens if you set the UpdateTargetID to the form's containing element).
The problem:
I can make both of those things work, but not at the same time. I can either have it always replace the current page, or always just replace the contents of the UpdateTargetId element. But I need it to be able to do either depending on whether the user successfully validated or not.
What I need
The ideal solution would be to be able to examine the result of the ajax request and determine whether to use the UpdateTargetId (replacing just the form) or not (replacing the whole page). I expect it would involve some work with jquery (assuming it's possible) but i'm not really that great with jquery yet to figure out how to do it myself. If it can't be done this way I'm also open to other methods/solutions for making it work in a similar fashion.
Thanks in advance ..
I two tables from database one as
user(id,first_name,last_name) and the second table
location(id,country).
I need to perform inner join with this two tables and the list should display first_name,last_name,country with condition user.id=location.id
I have written sql queries in cakephp
$this->set('users',$this->User->find('list', array(
'fields' => array('User.id', 'User.first_name','location.country'),
array('joins' => array(array('table' => 'location',
'alias' => 'location',
'type' => 'INNER',
'conditions' => array('User.id = location.id')))))));
i get error -Unknown column 'location.country' in 'field list'
Please help!
I have this code:
BufferedReader br =new BufferedReader(new FileReader("userdetails.txt"));
String str;
ArrayList<String> stringList = new ArrayList<String>();
while ((str=br.readLine())!=null){
String datavalue [] = str.split(",");
String category = datavalue[0];
String value = datavalue[1];
stringList.add(category);
stringList.add(value);
}
br.close();
it works when the variables category and value do not have a comma(,),however the values in the variable value does contain commas.Is there a way that I can split the index of the without using comma?
I have two basic SQL Server tables:
Customer (ID [pk], AddressLine1, AddressLine2, AddressCity, AddressDistrict, AddressPostalCode)
CustomerAddress(ID [pk], CustomerID [fk], Line1, Line2, City, District, PostalCode)
CustomerAddress contains multiple addresses for the Customer record.
For each Customer record I want to merge the most recent CustomerAddress record where most recent is determined by the highest CustomerAddress ID value.
I've currently got the following:
UPDATE Customer
SET
AddressLine1 = CustomerAddress.Line1,
AddressPostalCode = CustomerAddress.PostalCode
FROM Customer, CustomerAddress
WHERE
Customer.ID = CustomerAddress.CustomerID
which works but how can I ensure that the most recent (highest ID) CustomerAddress record is selected to update the Customer table?
I'm currently mining sequence patterns using SPADE algorithm in R.
SPADE is included in "arulesSequence" package of R.
I'm running R on my CentOS 6.3 64bit.
For an exercise,
I've tried an example presented in http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Sequence_Mining/SPADE
When I tried to do
"cspade(x, parameter = list(support = 0.4), control = list(verbose = TRUE))"
R says:
parameter specification:
support : 0.4
maxsize : 10
maxlen : 10
algorithmic control:
bfstype : FALSE
verbose : TRUE
summary : FALSE
preprocessing ... 1 partition(s), 0 MB [0.096s]
mining transactions ... 0 MB [0.066s]
reading sequences ...Error in asMethod(object) : 's' is not an integer vector
When I try to run SPADE on my Window 7 32bit,
it runs well without any error.
Does anybody know why such errors occur?
def maxVote(nLabels):
count = {}
maxList = []
maxCount = 0
for nLabel in nLabels:
if nLabel in count:
count[nLabel] += 1
else:
count[nLabel] = 1
#Check if the count is max
if count[nLabel] > maxCount:
maxCount = count[nLabel]
maxList = [nLabel,]
elif count[nLabel]==maxCount:
maxList.append(nLabel)
return random.choice(maxList)
nLabels contains a list of integers.
The above function returns the integer with highest frequency, if more than one have same frequency then a randomly selected integer from them is returned.
E.g. maxVote([1,3,4,5,5,5,3,12,11]) is 5
I am implementing hash table in C using linked list chaining method. The program compiles but when inserting a string in hash table, the program freezes and gets stuck. The program is below:
struct llist{
char *s;
struct llist *next;
};
struct llist *a[100];
void hinsert(char *str){
int strint, hashinp;
strint = 0;
hashinp = 0;
while(*str){
strint = strint+(*str);
}
hashinp = (strint%100);
if(a[hashinp] == NULL){
struct llist *node;
node = (struct llist *)malloc(sizeof(struct llist));
node->s = str;
node->next = NULL;
a[hashinp] = node;
}
else{
struct llist *node, *ptr;
node = (struct llist *)malloc(sizeof(struct llist));
node->s = str;
node->next = NULL;
ptr = a[hashinp];
while(ptr->next != NULL){
ptr = ptr->next;
}
ptr->next = node;
}
}
void hsearch(char *strsrch){
int strint1, hashinp1;
strint1 = 0;
hashinp1 = 0;
while(*strsrch){
strint1 = strint1+(*strsrch);
}
hashinp1 = (strint1%100);
struct llist *ptr1;
ptr1 = a[hashinp1];
while(ptr1 != NULL){
if(ptr1->s == strsrch){
cout << "Element Found\n";
break;
}
else{
ptr1 = ptr1->next;
}
}
if(ptr1 == NULL){
cout << "Element Not Found\n";
}
}
hinsert() is to insert elements into hash and hsearch is to search an element in the hash. Hash function is written inside hinsert() itself. In the main(), what i am initializing all the elements in a[] to be NULL like this:
for(int i = 0;i < 100; i++){
a[i] = NULL;
}
Help is very much appreciated. Thanks !
I have three tables and a range of two dates:
Services
ServicesClients
ServicesClientsDone
@StartDate
@EndDate
Services:
ID | Name
1 | Supervisor
2 | Monitor
3 | Manufacturer
ServicesClients:
IDServiceClient | IDClient | IDService
1 | 1 | 1
2 | 1 | 2
3 | 2 | 2
4 | 2 | 3
ServicesClientsDone:
IDServiceClient | Period
1 | 201208
3 | 201210
Period = YYYYMM
I need to insert into ServicesClientsDone the months range from @StartDate up @EndDate. I have also a temporary table (#Periods) with the following list:
Period
201208
201209
201210
The query I need is to give me back the following list:
IDServiceClient | Period
1 | 201209
1 | 201210
2 | 201208
2 | 201209
2 | 201210
3 | 201208
3 | 201209
4 | 201208
4 | 201209
4 | 201210
Which are client services but the ranks of the temporary table, not those who are already inserted
This is what i have:
Table periods:
DECLARE @i int
DECLARE @mm int
DECLARE @yyyy int,
DECLARE @StartDate datetime
DECLARE @EndDate datetime
set @EndDate = (SELECT GETDATE())
set @StartDate = (SELECT DATEADD(MONTH, -3,GETDATE()))
CREATE TABLE #Periods (Period int)
set @i = 0
WHILE @i <= DATEDIFF(MONTH, @StartDate , @EndDate )
BEGIN
SET @mm= DATEPART(MONTH, DATEADD(MONTH, @i, @FechaInicio))
SET @yyyy= DATEPART(YEAR, DATEADD(MONTH, @i, @FechaInicio))
INSERT INTO #Periods (Period)
VALUES (CAST(@yyyy as varchar(4)) + RIGHT('00'+CONVERT(varchar(6), @mm), 2))
SET @i = @i + 1;
END
Relation between ServicesClients and Services:
SELECT s.Name, sc.IDClient FROM Services
JOIN ServicesClients AS sc
ON sc.IDService = s.ID
Services already done and when:
SELECT s.Name, scd.Period FROM Services
JOIN ServicesClients AS sc
ON sc.IDService = s.ID
JOIN ServicesClientsDone AS scd
ON scd.IDServiceClient = sc.IDServiceClient
From the docs:
You usually access to-many
relationships using
mutableSetValueForKey:, which returns
a proxy object that both mutates the
relationship and sends appropriate
key-value observing notifications for
you.
So this returns an "intelligent" NSMutableSet which automatically lets the context delete objects when they get deleted from the set, and reverse? Is that a proxy object?
Hi folks,
I have a nested map:
Map<Integer, Map<Integer, Double>> areaPrices = new HashMap<Integer, Map<Integer, Double>>();
and this map is populated using the code:
while(oResult.next())
{
Integer areaCode = new Integer(oResult.getString("AREA_CODE"));
Map<Integer, Double> zonePrices = areaPrices.get(areaCode);
if(zonePrices==null)
{
zonePrices = new HashMap<Integer, Double>();
areaPrices.put(areaCode, zonePrices);
}
Integer zoneCode = new Integer(oResult.getString("ZONE_CODE"));
Double value = new Double(oResult.getString("ZONE_VALUE"));
zonePrices.put(zoneCode, value);
myBean.setZoneValues(areaPrices);
}
I want to use the value of this Map in another method of the same class. For that I have a bean.
How do I populate it on the bean, so that I can get the ZONE_VALUE in this other method
In my bean I added one new field as:
private Map<Integer, Map<Integer, Double>> zoneValues;
with getter and setter as:
public Map<Integer, Map<Integer, Double>> getZoneValues() {
return zoneValues;
}
public void setZoneValues(Map<Integer, Map<Integer, Double>> areaPrices) {
this.zoneValues = areaPrices;
}
What I am looking for to do in the other method is something like this:
Double value = myBean.get(areaCode).get(zoneCode);
How do I make it happen :(
I'd like the user to specify a RSS feed address and serialize the information from it. I am not interested in the XML format, but populate a strongly typed object from the XML. My question is, is there a standard that all RSS feeds support (Do all of them have date, title etc)? If so, is there a XSD that describes this. If not, how do I handle serializing a RSS feed to an object in ASP.NET?
int, char and bool usually have different sizes. Where intcharbool, I suppose.
But does the RAM even support this?
How is it built up?
Can it take advantage of bool being only 1 byte and store it in a small "register"?
pass=session("password")
Set objIns=server.CreateObject("adodb.connection")
objIns.Open session("Psrconnect")
inspass="Insert into passwords(pass) values ('&pass&')"
objIns.Execute(inspass)
i dont know what should be the syntax to pass the value stored in the variable. with this syntax, the value entered in the database is &pass&.
can anyone plz help me out?
I've been testing my app on a SQL Server 2005 database, and am trying to establish a preliminary picture of the query performance using sys.dm_exec_query_stats.
Problem: there's a particular query that I'm interested in, because total_elapsed_time and last_elapsed_time are both large numbers. When I tickle my app to invoke that query (this runs successfully), then refresh my view of the stats, I find that
1) execution_count has incremented (expected)
2) last_execution_time has updated to now (expected)
3) last_elapsed_time is still a large value (not expected - I anticipated a new value)
4) total_elapsed_time is unchanged (contradiction?)
If last_elapsed_time refers to the execution that happened @ last_execution_time, then the total_elapsed_time should have increased?
This documentation: http://msdn.microsoft.com/en-us/library/ms189741(SQL.90).aspx tells me that last_execution_time is the last time the plan was executed, and last_elapsed_time comes from the "most recently executed plan", but doesn't tell me why those might be different.
The query itself is uncomplicated (SELECT/WHERE/ORDER BY - parameters appearing in the where clause, but no clever operations), the table has maybe 25 rows in it right now.
Questions:
1) What's the real relationship between execution_count, last_execution_time, and last_elapsed_time?
2) Where is the documentation of this relationship (manual, third party book, blog, bug ticket, stone tablets...) ?
$("p").bind("click", function(event){
// code goes here
});
This is quite understandable. But what is the way to use a non-inline function and pass the event as an argument? That is:
$("p").bind("click", myFunction(event));
function myFunction(event) {
// code goes here
}
Thank you!
In C#, you can do the following:
List registers = new List { 1, 2, 3, 4 };
This will produce a list with 1, 2, 3, and 4 in the list. Suppose that I am given a list from some function and I want to insert a bunch of numbers like the following:
List register = somewhere();
register.Add(1);
register.Add(2);
register.Add(3);
register.Add(4);
Is there a cleaner way of doing this like the snippet above?
Hello all,
I need really your help please.
What I do is to build a table in html tags in my servlet then when trying to send this table to a servlet for the display using:
Response.sendRedirect this did not work.
I have an error but I don't know the cause.
I search to how do it since I use:
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<...");....
thinks a lot for your help
I can think of a number of ways to do this in PHP or even JavaScript, but I'm wondering if there's a SQL-based technique I'm overlooking.
I have a database table, let's say 20 fields X 10 rows. I want to display the entire table on an web page, so I'd do something like SELCT * FROM data_table;, and then format the result set using HTML table tags.
However, I'd also like to highlight values in the table based on whether they are the maximum or minimum value in their column. For example, I'd add bold tags around the max in each column. A resulting table might look something like this, with bold tags shown:
id | field1 | field2 | field3 | ...
0 | 5 | 2 | <b>7</b> | ...
1 | 3 | <b>8</b> | 6 | ...
2 | <b>9</b> | 5 | 1 | ...
...
I could do a separate SELECT with an ORDER BY for each field and then interpret the results, but that seems like a lot of extra DB access.
My alternative right now is to just fetch the whole table, and then sort/search for the highlight values using PHP.
Is there a better way?
I have table similar to the following:
Year | Product | Value
2006 A 10
2006 B 20
2006 C 30
2007 A 40
2007 B 50
2007 C 60
I would like a query that would return the following comparison
Product | 2006 Value | 2007 Value
A 10 40
B 20 50
C 30 60
What are the options to do so? Can it be done without joins?
I'm working with DB2, but answers in all SQL types would be helpful.
I'm creating a database access layer in native C++, and I'm looking at ways to support NULL values. Here is what I have so far:
class CNullValue
{
public:
static CNullValue Null()
{
static CNullValue nv;
return nv;
}
};
template<class T>
class CNullableT
{
public:
CNullableT(CNullValue &v) : m_Value(T()), m_IsNull(true)
{
}
CNullableT(T value) : m_Value(value), m_IsNull(false)
{
}
bool IsNull()
{
return m_IsNull;
}
T GetValue()
{
return m_Value;
}
private:
T m_Value;
bool m_IsNull;
};
This is how I'll have to define functions:
void StoredProc(int i, CNullableT<int> j)
{
...connect to database
...if j.IsNull pass null to database etc
}
And I call it like this:
sp.StoredProc(1, 2);
or
sp.StoredProc(3, CNullValue::Null());
I was just wondering if there was a better way than this. In particular I don't like the singleton-like object of CNullValue with the statics.
I'd prefer to just do
sp.StoredProc(3, CNullValue);
or something similar. How do others solve this problem?