Where can I find a code to parse URL queries in C++?
For example: "id=34&name=test&size=367"
And something like 'getvalue(parser_query, "name")' that returns 'test'.
Thanks.
I have a table, whose fields are
id, name, link
the link holds the name of the page like "link" = "index.php". Now I want to update this field
and add "page=" in front of "index.php". Using this method I would like to update every entry in my table.
My desired SQL syntax need to be something like this
UPDATE mytable set link= 'page=' + <existing value of link> WHERE 1;
I am using 'WHERE 1;' to denote every row.
Anyone know how to accomplish this?
Ok, this is probably really simple, but I just can't figure it out. I have a primary key in a table that goes from 1-5,000. I need to manually update that id (for other table update purposes) so that it says 5,000-10,000. Can't I manually update this column? Please help!!! Thank you
The problem here consists of translating a statement written in LINQ to SQL syntax into the equivalent for NHibernate. The LINQ to SQL code looks like so:
var whatevervar = from threads in context.THREADs
join threadposts in context.THREADPOSTs
on threads.thread_id equals threadposts.thread_id
join posts1 in context.POSTs
on threadposts.post_id equals posts1.post_id
join users in context.USERs
on posts1.user_id equals users.user_id
orderby posts1.post_time
where threads.thread_id == int.Parse(id)
select new
{
threads.thread_topic,
posts1.post_time,
users.user_display_name,
users.user_signature,
users.user_avatar,
posts1.post_body,
posts1.post_topic
};
It's essentially trying to grab a list of posts within a given forum thread. The best I've been able to come up with (with the help of the helpful users of this site) for NHibernate is:
var whatevervar = session.CreateQuery("select t.Thread_topic, p.Post_time, " +
"u.User_display_name, u.User_signature, " +
"u.User_avatar, p.Post_body, p.Post_topic " +
"from THREADPOST tp " +
"inner join tp.Thread_ as t " +
"inner join tp.Post_ as p " +
"inner join p.User_ as u " +
"where tp.Thread_ = :what")
.SetParameter<THREAD>("what", threadid)
.SetResultTransformer(Transformers.AliasToBean(typeof(MyDTO)))
.List<MyDTO>();
But that doesn't parse well, complaining that the aliases for the joined tables are null references. MyDTO is a custom type for the output:
public class MyDTO
{
public string thread_topic { get; set; }
public DateTime post_time { get; set; }
public string user_display_name { get; set; }
public string user_signature { get; set; }
public string user_avatar { get; set; }
public string post_topic { get; set; }
public string post_body { get; set; }
}
I'm out of ideas, and while doing this by direct SQL query is possible, I'd like to do it properly, without defeating the purpose of using an ORM.
Thanks in advance!
EDIT:
The database looks like this: http://i41.tinypic.com/5agciu.jpg (Can't post images yet.)
I have a column using IDs that I want to sort by. It has ID values from 1 to 3. However, instead of just using ASC of DESC, I want to do a custom sort by 2, 3, 1. How do I make this happen?
I am using OleDB for executing my queries in C#,
Is there any way I can execute multiple queries in one command statement?
I tried to separate them with semi-colon (;) but it gives error "Characters found at the end"
I have to execute a few hundreds of queries at once.
I have these rows in a table
ID Name Price Delivery
== ==== ===== ========
1 apple 1 1
2 apple 3 2
3 apple 6 3
4 apple 9 4
5 orange 4 6
6 orange 5 7
I want to have the price at the third delivery (Delivery=3) or the last price if there's no third delivery.
It would give me this :
ID Name Price Delivery
== ==== ===== ========
3 apple 6 3
6 orange 5 7
I don't necessary want a full solution but an idea of what to look for would be greatly appreciated.
Hey everyone. I'm currently preparing for my exams and would like to know some examples of user-defined integrity rule in database systems. As far as I understand, it means that I can set up certain conditions for the columns and when data is inserted it needs to fulfill these conditions.
For example: if I set up a rule that an ID needs to consist of 5 integers ONLY then when I insert a row with ID which is made up of integers and some chars then it won't accept it and return an error.
Could someone confirm and give me some opinion on that? Thank you very much in advance!
I'm trying to create a script that allows me to upload an image, grab the details sent through inputs (a description and chosen project number) and insert this information into a table. I currently have this function:
public function NewEntry() {
$connect = new dbconnect;
$_SESSION['rnd'] = substr(number_format(time() * rand(),0,'',''),0,15);
$allowedExts = array("gif", "jpeg", "jpg", "png");
$size = $_FILES["file"]["size"];
$path = $_FILES["file"]["name"];
$extension = pathinfo($path, PATHINFO_EXTENSION);
$pr = $_POST['project'];
$cl = $_POST['changelog'];
$file = $_SESSION['rnd'] . "." . $extension;
if (in_array($extension, $allowedExts) && $size < 200000000) {
if ($_FILES["file"]["error"] == 0) {
if (!file_exists("../uploads/" . $_SESSION['rnd'])) {
move_uploaded_file($_FILES["file"]["tmp_name"], "../uploads/" . $_SESSION['rnd'] . "." . $extension);
}
}
} else {
echo "File validation failed.";
}
$row = $connect->queryExecute("INSERT INTO entries(project,file,changelog)VALUES($pr,$file,$cl)");
header('location:http://www.example.com/admin');
}
When the form is posted the function runs, the image uploads but the query isn't executed.
The dbconnect class isn't at fault as it's untampered and has been used in past projects. The error logs don't give any output and no MySQL errors show. Any ideas?
I have a situation that I'm sure is quite common and it's really bothering me that I can't figure out how to do it or what to search for to find a relevant example/solution. I'm relatively new to MySQL (have been using MSSQL and PostgreSQL earlier) and every approach I can think of is blocked by some feature lacking in MySQL.
I have a "log" table that simply lists many different events with their timestamp (stored as datetime type). There's lots of data and columns in the table not relevant to this problem, so lets say we have a simple table like this:
CREATE TABLE log (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(16),
ts DATETIME NOT NULL,
eventtype VARCHAR(25),
PRIMARY KEY (id)
)
Let's say that some rows have an eventtype = 'start' and others have an eventtype = 'stop'. What I want to do is to somehow couple each "startrow" with each "stoprow" and find the time difference between the two (and then sum the durations per each name, but that's not where the problem lies). Each "start" event should have a corresponding "stop" event occuring at some stage later then the "start" event, but because of problems/bugs/crashed with the data collector it could be that some are missing. In that case I would like to disregard the event without a "partner". That means that given the data:
foo, 2010-06-10 19:45, start
foo, 2010-06-10 19:47, start
foo, 2010-06-10 20:13, stop
..I would like to just disregard the 19:45 start event and not just get two result rows both using the 20:13 stop event as the stop time.
I've tried to join the table with itself in different ways, but the key problems for me seems to be to find a way to correctly identify the corresponding "stop" event to the "start" event for the given "name". The problem is exactly the same as you would have if you had table with employees stamping in and out of work and wanted to find out how much they actually were at work. I'm sure there must be well known solutions to this, but I can't seem to find them...
How can i concate this string in mysql
desc=desc+$desct
what i want is each time i insert a variable from PHP that the string is added to the string which was already in db and seperated with ||
the field desc should look like this
desc
10||30||90||710
say i want to add the value 20
desc
10||30||90||710||20
then the desc field should look like this
How can i implement this?
So I have a SQliteDatabase mDb. It only has one column, and its data are Strings for previously saved inputs. I'm trying to populate all the data from mDb into a String[] for AutoCompleteTextView (so that the autocomplete is based on previous inputs), and here's my code to get all of the String.
public String[] fetchAllSearch() {
ArrayList<String> allSearch = new ArrayList<String>();
Cursor c = mDb.rawQuery("select * from " + DATABASE_TABLE, null);
c.moveToFirst();
if (c.getCount() > 0) {
do {
allSearch.add(c.getString(c.getColumnIndex("KEY")));
} while (c.moveToNext());
}
String[] foo = (String[]) allSearch.toArray();
if (foo == null) {
foo = new String[] {""};
}
return foo;
}
my CREATE_TABLE command is
private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE;
..
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
But for some reason the line mDb.rawQuery(...) is giving me "no such table found" exception, and for the life of me I can't figure out why. Any pointers?
Hello,
Im trying to insert data into a table in MySQL. I found/modified some code from w3Schools and still couldn't get it working. Heres what I have so far:
<?php
$rusername=$_POST['username'];
$rname=$_POST['name'];
$remail=$_POST['emailadr'];
$rpassword=$_POST['pass'];
$rconfirmpassword=$_POST['cpass'];
if ($rpassword==$rconfirmpassword) {
$con = mysql_connect("host","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydbname ", $con);
}
mysql_query("INSERT INTO members (id, username, password)
VALUES ('4', $rusername, $rpassword)");
?>
Did I mistype something? To my understanding "members" is the name of the table. If anyone knows whats wrong I appreciate the help.
Thanks
I have 300 boolean fields in one table, and im trying to do somithing like that:
One string field:
10000010000100100100100100010001
Ha a simple way to do a simple search os this field like:
select * from table where field xor "10000010000100100100000000010001"
Im tring this but is to long:
select * from teste where mid(info,2,1) and mid(info,3,1)
:) Help!!
I want be able to find tags of items under the a certain category. Following is example of my database design:
images
+----------+-----+-------------+-----+
| image_id | ... | category_id | ... |
+----------+-----+-------------+-----+
| 1 | ... | 11 | ... |
+----------+-----+-------------+-----+
| 2 | ... | 12 | ... |
+----------+-----+-------------+-----+
| 3 | ... | 11 | ... |
+----------+-----+-------------+-----+
| 4 | ... | 11 | ... |
+----------+-----+-------------+-----+
images_tags
+----------+--------+
| image_id | tag_id |
+----------+--------+
| 1 | 53 |
+----------+--------+
| 3 | 54 |
+----------+--------+
| 2 | 55 |
+----------+--------+
| 1 | 56 |
+----------+--------+
| 4 | 57 |
+----------+--------+
tags and categories each have their own table relating the id to an actual name(text).
So my question is how will i find out that images with category_id=11 have have the tag_id 53 54 55 56 57.
In other words how to find the tags that images in certain category have?
Hello,
I have a database full of rows like
id,action,date
2,2,2010-03-01
3,2,2010-03-01
4,3,2010-03-01
5,3,2010-03-01
6,4,2010-02-01
7,4,2010-02-01
And I want to select all the count all the 2's and all the 3's and all the 4's. But I don't want to have to do 3 different SELECT COUNT() commands, is there a way to do this in a single command?
Note, I want to display this as something like
Action 2 = 2
Action 3 = 2
Action 4 = 2
(etc etc).
And I will also need to specific a date (so it only counts all the 2,3,4,etc for dates between 2010-02-03 and 2010-03-01 for example)
I'm having a small trouble since it was a long time ago i studies databases and querys.
For example i'll have two tables for cd:s, one with data and one with alternative translations.
In the CD-table i have the original language, and it looks something like this
Table for CDs (cds):
id | name | language
-----------------------
1 | aaa | en
2 | bbb | en
3 | ccc | fi
Table for languages (languages):
cd_id | language | name
-----------------------
1 | fi | AAA
1 | de | AAACHTUNG
3 | en | CCC
Now, i want to get all these cd:s in for example german, if there's no translation made i want it to be in the original language...
How can i do this?
Lets say I have the following mapping:
<hibernate-mapping package="mypackage">
<class name="User" table="user">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="name" />
<property name="age" />
</class>
</hibernate-mapping>
Is it possible to select the oldest user (that is age is maximal) using Criteria in Hibernate?
I can imagine that i could do this with 2 selects. (first select total number of users and then order the entries descending by age and select the first entry). But is it possible with a single select?
Thank you
Palo
Hi. Code not working because of async query and variable scope problem. I can't understand how to solve this. Change to $.ajax method with async:false - not an option. I know about closures, but how I can implement it here - don't know. I've seen all topics here about closures in js and jQuery async problems - but still nothing. Help, please.
Here is the code:
var map = null;
var marker;
var cluster = null;
function refreshMap()
{
var markers = [];
var markerImage = new google.maps.MarkerImage('/images/image-1_32_t.png', new google.maps.Size(32, 32));
$.get('/get_users.php',{},function(data){
if(data.status == 'error')
return false;
var users = data.users; // here users.length = 1 - this is ok;
for(var i in users)
{
//here I have every values from users - ok
var latLng = new google.maps.LatLng(users[i].lat, users[i].lng);
var mark = new google.maps.Marker({
position: latLng,
icon: markerImage
});
markers.push(mark);
alert(markers.length); // length 1
}
},'json');
alert(markers.length); // length 0
//if I have alert() above - I get result
cluster = new MarkerClusterer(map, markers,
{
maxZoom: null,
gridSize: null
});
}
Thanks.
Have a LinqtoSql query that I now want to precompile.
var unorderedc =
from insp in sq.Inspections
where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime
&& insp.Model == "EP" && insp.TestResults != "P"
group insp by new { insp.TestResults, insp.FailStep } into grp
select new
{
FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0),
CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0),
grp.Key.TestResults,
grp.Key.FailStep,
PercentFailed = Convert.ToDecimal(1.0 * grp.Count() / tcount * 100)
};
I have created this delegate:
public static readonly Funct<SQLDataDataContext, int, string, string, DateTime, DateTime, IQueryable<CalcFailedTestResult>>
GetInspData = CompiledQuery.Compile((SQLDataDataContext sq, int tcount, string strModel, string strTest, DateTime dStartTime,
DateTime dEndTime, IQueryable<CalcFailedTestResult> CalcFailed) =>
from insp in sq.Inspections
where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime
&& insp.Model == strModel && insp.TestResults != strTest
group insp by new { insp.TestResults, insp.FailStep } into grp
select new
{
FailedCount = (grp.Key.TestResults == "F" ? grp.Count() : 0),
CancelCount = (grp.Key.TestResults == "C" ? grp.Count() : 0),
grp.Key.TestResults,
grp.Key.FailStep,
PercentFailed = Convert.ToDecimal(1.0 * grp.Count() / tcount * 100)
});
The syntax error is on the CompileQuery.Compile() statement
It appears to be related to the use of the select new {} syntax.
In other pre-compiled queries I have written I have had to just use the select projection by it self. In this case I need to perform the grp.count() and the immediate if logic.
I have searched SO and other references but cannot find the answer.
Hello,
*EDIT*Thanks to the comments below it has been figured out that the problem lies with the md5, without everything works as it should.
But how do i implent the md5 then?
I am having some troubles with the following code below to login.
The database and register system are already working.
The problem lies that it does not find any result at all in the query.
IF the count is 0 it should redirect the user to a secured page.
But this only works if i write count = 0, but this should be 0 , only if the user name and password is found he should be directed to the secure (startpage) of the site after login.
For example root (username) root (password) already exists but i cannot seem to properly login with it.
<?php
session_start();
if (!empty($_POST["send"]))
{
$username = ($_POST["username"]);
$password = (md5($_POST["password"]));
$count = 0;
$con = mysql_connect("localhost" , "root", "");
mysql_select_db("testdb", $con);
$result = mysql_query("SELECT name, password FROM user WHERE name = '".$username."' AND password = '".$password."' ")
or die("Error select statement");
$count = mysql_num_rows($result);
if($count > 0) // always goes the to else, only works with >=0 but then the data is not found in the database, hence incorrect
{
$row = mysql_fetch_array($result);
$_SESSION["username"] = $row["name"];
header("Location: StartPage.php");
}
else
{
echo "Wrong login data, please try again";
}
mysql_close($con);
}
?>