i have a asp.net mvc website which runs a number of queries for each page. Should i open up a single connection or open and close a connection on each query?
As LINQ is a good query language in dot net and everyone should be able to work with it.
What are the necessary abilities which a programmer should have, before start learning LINQ.
And after that, What should he know about LINQ? (important tips)
Hello,
I'm trying to copy the contents of one table into another in Postgres, however it appears some rows aren't being copied correctly:
ActiveRecord::StatementInvalid:
PGError: ERROR: column "email_date" is
of type timestamp without time zone
but expression is of type character
varying HINT: You will need to rewrite
or cast the expression.
Is there any way I can have it automatically skip (or ignore) invalid rows?
Here's the query I'm using:
SET statement_timeout = 0; INSERT INTO emails3 SELECT * FROM emails
Hi,
I have a table of items stored this way :
A1 | B1
A1 | B2
A1 | B3
A2 | B1
A2 | B4
...
And I need to retrieve with a SQL Query :
A1 | B1, B2, B3
A2 | B1, B4
...
HI
One of my requirement is to have prefix on all the tables of the django based project (Because db is hosted on shared server). I have used db_table Meta option to set the prefix for the tables which I have created.
Now my query is how do I set the prefix for tables provided by django.contrib.
Instead of auth_group django should create prefix_auth_group.... How do I do that?
Thank you very much...
I have in my model:
def presenter
@presenter ||= ProfilePresenter.new(self)
@presenter
end
The ProfilePresenter is a class that has methods like, get_link(), get_img_url(size), get_sex(), get_relationship_status() and other methods that have not to do with the model, not even with the controller but is used multiple times in the view.
So now i use them by doing this:
Profile.presenter.get_link
# or
Profile.presenter.get_img_url('thumb') # returns the path of the image. is not used to make a db query
I have a code below where it logs a teacher in by matching it's username and password in the database, if correct, then log in, if incorrect, then display a message.
<?php
session_start();
$username="xxx";
$password="xxx";
$database="mobile_app";
$link = mysqli_connect('localhost',$username,$password);
mysqli_select_db($link, $database) or die( "Unable to select database");
foreach (array('teacherusername','teacherpassword') as $varname) {
$$varname = (isset($_POST[$varname])) ? $_POST[$varname] : '';
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" id="teachLoginForm">
<p>Username</p><p><input type="text" name="teacherusername" /></p> <!-- Enter Teacher Username-->
<p>Password</p><p><input type="password" name="teacherpassword" /></p> <!-- Enter Teacher Password-->
<p><input id="loginSubmit" type="submit" value="Login" name="submit" /></p>
</form>
<?php
if (isset($_POST['submit'])) {
$query = "
SELECT * FROM Teacher t
WHERE
(t.TeacherUsername = '".mysqli_real_escape_string($teacherusername)."')
AND
(t.TeacherPassword = '".mysqli_real_escape_string($teacherpassword)."')
";
$result = mysqli_query($link, $query);
$num = mysqli_num_rows($result);
$loged = false;
while($row = mysqli_fetch_array($result))
{
if ($_POST['teacherusername'] == ($row['TeacherUsername']) && $_POST['teacherpassword'] == ($row['TeacherPassword']))
{
$loged = true;
}
$_SESSION['teacherforename'] = $row['TeacherForename'];
$_SESSION['teachersurname'] = $row['TeacherSurname'];
$_SESSION['teacherusername'] = $row['TeacherUsername'];
}
if ($loged == true){
header( 'Location: menu.php' ) ;
}else{
echo "The Username or Password that you Entered is not Valid. Try Entering it Again.";
}
mysqli_close($link);
}
?>
Now the problem is that even if the teacher has entered in the correct username and password, it still doesn't let the teacher log in. When the code above was the old mysql() code, it worked fine as teacher was able to login when username and password match, but when trying to change the code into mysqli then it causes login to not work even though username and password match. What am I doing wrong?
I am trying to use open query to run a stored procedure in a remote database, and insert it into a table in my local database:
-- this works
exec remotesvr.sys.dbo.golden_table 'some', 'parameters'
While the above works out, I try the following:
insert into my_local_table
exec remotesvr.sys.dbo.golden_table 'some', 'parameters'
I get a SQL error to the effect of 'unable to begin a distributed transaction'.
Is there any way around this?, i.e. can I execute take the results of a remote stored procedure and put its contents in a local table?
Is it possible to execute the two update queries in phpmyadmin together?
Like wise
UPDATE jos_menu SET home = 0 WHERE 1;
UPDATE jos_menu SET home = 1 WHERE id = 9;
Now can we copy both these queries together and Run it on phpmyadmin sql query panel?
will it be executed?
Heya,
I'm fetching a page using ajax (jquery) and appending certain data to the Requests query string to let the server know it shouldn't render the entire Page, just the view in question to the output buffer. I'm having no luck though, I can detect when the page needs to be rendered partially, but everything I've tried so far (including stuff like return PartialView()) isn't working.
Any ideas?
Thanks in advance.
I am doing a query with three tables, the problem was one table has many occurrences of id of another.
sample data:
users: id
answers:
id:1
user_answer :1
id:1
user_answer :2
id:1
user_answer :3
Questions:
id:1
answers :answer description
id:2
answers :answer description
id:3
answers :answer description
How can I get all user information and all answer and its description, I used GROUP by user.id but it only returns only one answer.
I want to return something like this list all of users answer:
Name Q1 Q2
USERNAME ans1,ans2 ans1,ans2 comma separated description of answer here
I have an SQL query that has an alias in the SELECT statement
SELECT
CONCAT(YEAR(r.Date),_utf8'-',_utf8'Q',QUARTER(r.Date)) AS 'QuarterYear'
Later, I want to refer to this in my group by statement.
I'm a little confused...should I wrap this with backticks, single quote or just leave it unwrapped int he group by
GROUP BY
`QuarterYear `
or should I do this?:
GROUP BY
'QuarterYear'
or just this?:
GROUP BY
QuarterYear
Hi, i have a table like this:
Table(MissioneID, Type)
Type can be 1,2 or 3
i have to count missions by type value:
ex. if table's content is:
MissioneID Type
1,1
1,2
1,1
2,3
1,2
The result of query is
MissioneID,Count1,Count2,Count3
1, 2,2,0
2,0,0,1
How can i do?
thanks
I'm trying to take a query:
SHOW TABLES;
which will display a bunch of tables with the chat_ prefix. I want to remove the chat_ prefix from the string, format the variable (with a link), and display it. How is this accomplished?
Is there a query I can write against an INFORMATION_SCHEMA or against the system tables to determine if a column is an identity column in SQL CE version 3.5?
I have the following linq query
from o in context.Opportunities
join i in context.Interactions on o.OpportunityID equals i.OpportunityID into ints
from i in ints.DefaultIfEmpty()
orderby i.StatusID descending, o.StatusID descending
select o
Now i want to then do a distinct on the opportunities table but doing so removes my orderby. I know that you can do Distinct().OrderBy but how do i get a reference to the interactions table that was joined when I'm only selecting the opportunity entity?
I want to convert my Resultset to List in my JSP page. and want to display all the values. This is my query:
SELECT userId, userName
FROM user;
I have executed that using preparedstatement and got the Resultset. But how to convert it as a List and want to display the result like this:
userID userName
------------------
1001 user-X
1006 user-Y
1007 user-Z
I'm learning how to use SQL Server Management Studio and can't figure out how to insert a new row into a table.
Table Structure:
ID,
Field1,
Field2
Query:
INSERT INTO Table (Field1,Field2) VALUES(1,2)
Error:
Major Error 0x80040E14, Minor Error 25503
I'm probably missing something very noobie like. Any help would be appreciated.
I'm not able to figure out the difference between these queries. I'm pretty sure that the first one is an equi-join. I'm not sure how the second one ISN'T the same as the first.
The sub query in #2 selects all Ids from S, and then it returns all R's that also have those ID's, no?
SELECT R.cname
FROM R, S,
WHERE R.Id = S.Id
SELECT R.cname
FROM R
WHERE R.Id IN (SELECT S.Id FROM S)
I have a query:
SELECT Content.content_name, Language2.Name, Language2.language_id,
Content.id, Content.content_description,
FROM Language AS Language2
LEFT JOIN contents AS Content ON (Language2.language_id = Content.language_id)
How do I select only the distinct content_name?
I'm trying to recreate a race condition in a test, so I can try out some solutions. I find that in the threads I create in my test, ActiveRecord always returns 0 for counts and nil for finds. For example, with 3 rows in the table "foos":
it "whatever" do
puts Foo.count
5.times do
Thread.new do
puts Foo.count
end
end
end
will print
3
0
0
0
0
0
test.log shows the expected query, the expected 6 times:
SELECT count(*) AS count_all FROM `active_agents`
Any idea what's going on here?
Hi,
I'm writing sql query to my SqlCommand, and some part of them looks like:
WHERE Path like N'+(select top 1 path from [Paths] where objectcode=@objectCode and objecttype=@objectType)+%' order by path desc,objecttype desc
I get no records , bu when I wrote the same in sql server 2005 i have plenty rows...
where path like (select top 1 path from [Paths] where objectcode='eg' and objecttype='0')+'%'
order by path desc
What's wrong ??
@objectType is 'eg'
Hi!
I'm writing a static page controller.
I get the menuname in the routes.rb and it's call the static controller show method.
match '/:menuname' = 'static#show'
And static_controller.rb:
@static=Staticpage.where("menuname =
?", params[:menuname])
But if I want print @static.title in the view, I get this error:
undefined method `title' for #
Whats wrong?
the SQL query looks good:
SELECT staticpages.* FROM staticpages WHERE (menuname = 'asd')
How would I write a SQLite query to select all records from a specific month?
My dates are stored as Unix timestamps. PHP code is allowed in your solution if it's required. SQLite2-compatible queries only, please. :)