I'm looking for a Java ORM that works from database reflection - I need to just point it at a DB, and start being able to walk through the entire set of tables, etc.
Ideas?
I need to get the most recent record for each device from an upgrade request log table. A device is unique based on a combination of its hardware ID and its MAC address. I have been attempting to do this with GROUP BY but I am not convinced this is safe since it looks like it may be simply returning the "top record" (whatever SQLite or MySQL thinks that is).
I had hoped that this "top record" could be hinted at by way of ORDER BY but that does not seem to be having any impact as both of the following queries returns the same records for each device, just in opposite order:
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created DESC
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created ASC
Is there another way to accomplish this? I've seen several somewhat related posts that have all involved sub selects. If possible, I would like to do this without subselects as I would like to learn how to do this without that.
My table looks like this with duplicates in col1
col1, col2, col3, col4
1, 1, 0, a
1, 2, 1, a
1, 3, 1, a
2, 4, 1, b
3, 5, 0, c
I want to select distinct col1 with max (col3) and min(col2);
so result set will be:
col1, col2, col3, col4
1, 2, 1, a
2, 4, 1, b
3, 5, 0, c
I have a solution but looking for best ideas?
Hi
I am using Linq2Sql and want to bind an objects field (which is enum) to either a bit or a int type in the database. For example I want have a gender field in my model. I have already edited the DBML and changed the Type to point to my enum. I want to create Radio buttons (which I think I have figured out) for gender and dropdown lists for other areas using the same idea. My enum looks like this
public enum Gender
{
Male,
Female
}
Mapping between DbType 'int' and Type 'Project.Models.Gender' in Column 'Gender' of Type 'Candidate' is not supported.
Any ideas on how to do this mapping. Am I missing something on the enums.
I've written some really nice, funky libraries for use in LinqToSql. (Some day when I have time to think about it I might make it open source... :) )
Anyway, I'm not sure if this is related to my libraries or not, but I've discovered that when I have a large number of changed objects in one transaction, and then call DataContext.GetChangeSet(), things start getting reaalllly slooowwwww. When I break into the code, I find that my program is spinning its wheels doing an awful lot of Equals() comparisons between the objects in the change set. I can't guarantee this is true, but I suspect that if there are n objects in the change set, then the call to GetChangeSet() is causing every object to be compared to every other object for equivalence, i.e. at best (n^2-n)/2 calls to Equals()...
Yes, of course I could commit each object separately, but that kinda defeats the purpose of transactions. And in the program I'm writing, I could have a batch job containing 100,000 separate items, that all need to be committed together. Around 5 billion comparisons there.
So the question is: (1) is my assessment of the situation correct? Do you get this behavior in pure, textbook LinqToSql, or is this something my libraries are doing? And (2) is there a standard/reasonable workaround so that I can create my batch without making the program geometrically slower with every extra object in the change set?
Scenario: I have a fairly generic table (Data), that has an identity column. The data in this table is grouped (lets say by city).
The users need an identifier in order for printing on paper forms, etc.
The users can only access their cites data, so if they use the identity column for this purpose they will see odd numbers (e.g. a 'New York' user might see 1,37,2028... as the listed keys.
Idealy they would see 1,2,3... (or something similar)
The problem of course is concurrency, this being a web application you can't just have something like:
UserId = Select Count(*)+1 from Data Where City='New York'
Has anyone come up with any cunning ways around this problem?
This is a very strange problem and i really dont have a clue whats causing it.
What is supposed to happen is that a call to the BLL then DAL returns some data via a linq SPROC call. The retunred IMultipleResults object is processed and all results stored in a hashtable.
The hashtable is stored in session and then the UI layer uses these results to dynamically generate some gridviews.
Easy you would think.
But if i run the code i dont get any gridviews. If i take out the call to the BLL and DAL the gridviews appear but with nothing in them?
Why is it the page renders correctly when i take out the call to get the data?
Thanks.
iam having 2 tables
table Items Table (this table holds all items iam having)
itemId
---------
Item1
Item2
Item3
Item4
Item5
table 2 users_item relation
UserId || ItemId
1 || Item1
1 || Item2
userId one has stored 2 items Item1,Item2.
Now i want to write a query on table1 (Items table) so that it displays all items which user1 has NOT chosen.
I try to request an array of IDs, to return each row with that ID, and push each into an Array $finalArray
But only the first result from the Query will output, and at the second foreach, it skips the while loop.
I have this working in another script, so I don't understand where it's going wrong.
The $arrayItems is an array containing: "home, info"
$finalArray = array();
foreach ($arrayItems as $UID_get)
{
$Query = "SELECT *
FROM items
WHERE (uid = '" . cleanQuery($UID_get) . "' )
ORDER BY uid";
if($Result = $mysqli->query($Query))
{
print_r($UID_get);
echo "<BR><-><BR>";
while ($Row = $Result->fetch_assoc())
{
array_push($finalArray , $Row);
print_r($finalArray );
echo "<BR><><BR>";
}
}
else
{
echo '{ "returned" : "FAIL" }'; //. mysqli_connect_errno() . ' ' . mysqli_connect_error() . "<BR>";
}
}
(the cleanQuery is to escape and stripslashes)
What I'm trying to get is an array of multiple rows (after i json_encoded it, like:
{"finalArray" : { "home": {"id":"1","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"red\" }"} }, { "info": {"id":"2","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"blue\" }"} } }
But that's after I get both, or more results from the db.
the print_r($UID_get); does print info, but then nothing..
So, why am I not getting the second row from info? I am essentially re-querying foreach $arrayItem right?
i have a database that already has a users table
COLUMNS:
userID - int
loginName - string
First - string
Last - string
i just installed the asp.net membership table. Right now all of my tables are joined into my users table foreign keyed into the "userId" field
How do i integrate asp.net_users table into my schema? here are the ideas i thought of:
Add a membership_id field to my users table and on new inserts, include that new field in my users table. This seems like the cleanest way as i dont need to break any existing relationships.
break all existing relationship and move all of the fields in my user table into the asp.net_users table. This seems like a pain but ultimately will lead to the most simple, normalized solution
any thoughts?
Setup:
mysql> create table t(a integer unsigned,b integer unsigned);
mysql> insert into t(a,b) values (1,2),(1,3),(2,4);
mysql> create index i_t_a on t(a);
mysql> create index i_t_b on t(b);
mysql> explain select * from t where a=1 or b=4;
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t | ALL | i_t_a,i_t_b | NULL | NULL | NULL | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
Is there something I'm missing?
Update
mysql> explain select * from t where a=1 or b=4;
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t | ALL | i_t_a,i_t_b | NULL | NULL | NULL | 1863 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
Version:
mysql> select version();
+----------------------+
| version() |
+----------------------+
| 5.1.36-community-log |
+----------------------+
Has anyone ever successfully make index merge work for MySQL?
I'll be glad to see successful stories here:)
I'm importing a flat file of invoices into a database using C#. I'm using the TransactionScope to roll back the entire operation if a problem is encountered.
It is a tricky input file, in that one row does not necessary equal one record. It also includes linked records. An invoice would have a header line, line items, and then a total line. Some of the invoices will need to be skipped, but I may not know it needs to be skipped until I reach the total line.
One strategy is to store the header, line items, and total line in memory, and save everything once the total line is reached. I'm pursuing that now.
However, I was wondering if it could be done a different way. Creating a "nested" transaction around the invoice, inserting the header row, and line items, then updating the invoice when the total line is reached. This "nested" transaction would roll back if it is determined the invoice needs to be skipped, but the overall transaction would continue.
Is this possible, practical, and how would you set this up?
i have a data-gride-view and i add my query to this when write my query i catch this error:
The schema returned by the new query differs from the base query
and this my query:
SELECT B.SettingKey, 'SysSettingsDep' AS TableName, B.SettingValue, B.SettingDesc
FROM SysCustomer AS A INNER JOIN
SysSettingsDep AS B ON A.SettingKey = B.SettingKey
UNION
SELECT C.SettingKey, 'SysSettingsMachine' AS TableName, C.SettingValue, C.SettingDesc
FROM SysCustomer AS A INNER JOIN
SysSettingsMachine AS C ON A.SettingKey = C.SettingKey
UNION
SELECT D.SettingKey, 'SysSettings' AS TableName, D.SettingValue, D.SettingDesc
FROM
SysCustomer AS A INNER JOIN SysSettings AS D ON A.SettingKey = D.SettingKey
help me to solve this,
tnx
I would like to make notice of some wierd thing. I designed an entire package application using VB.Net in Visual Studio 2008. I changed the normal backgrounds to Black, to make a diffrerence. but the problem is i1mm getting changing back ground colors when i install it on other systems.which does have all supports required.
What should i do to supress this problem.
UPDATE polls_options SET `votes`=`votes`+1, `percent`=ROUND((`votes`+1) / (SELECT voters FROM polls WHERE poll_id=? LIMIT 1) * 100,1)
WHERE option_id=?
AND poll_id=?
Don't have table data yet, to test it properly. :)
And by the way, in what type % integers should be stored in database?
Thanks for the help!
Using MySql 5, I have a task where I need to update one table based on the contents of another table.
For example, I need to add 'A1' to table 'A' if table 'B' contains 'B1'. I need to add 'A2a' and 'A2b' to table 'A' if table 'B' contains 'B2', etc.. In our case, the value in table 'B' we're interested is an enum.
Right now I have a stored procedure containing a series of statements like:
INSERT INTO A
SELECT 'A1'
FROM B
WHERE B.Value = 'B1';
--Repeat for 'B2' -> 'A2a'; 'B2' -> 'A2b'; 'B3' -> 'A3', etc...
Is there a nicer more DRY way of accomplishing this?
Edit:
There may be values in table 'B' that have no equivalent value for table 'A'.
Hi,
Does order of the columns in an Index definition for a table in a database has any effect on the performance?
for e.g. are these two queries different ?
CREATE INDEX xxx ON tablex(col1,col2)
CREATE INDEX xxx ON tablex(col2,col1)
what about the in case that I use a BTREE index?
I am using Mysql.
thanks
i am converting from access to mysql
i have a table in access where one of the columns is an autonumber
when i transfer the data into the mysql database (where i also have a column that is auto_increment), should i be transfering the auto_increment data into the auto_increment column, or will it auto_increment itself?
how do i ensure that if i do not transfer the autoincrement data from access, that it auto_increments properly?
i have one independent form where i am checking read only access of an xml file ,
if the file is read only then i have to display message in the status bar of MDI form.
since i am using independent form to valid xml file, status bar of the MDI form is not displaying the error message.
now how to display message?
thanx in advance
I have a mysql table "items" with 2 integer fields: seid and tiid
The table has about 35000000 records, so it's very large.
seid tiid
-----------
1 1
2 2
2 3
2 4
3 4
4 1
4 2
The table has a primary key on both fields, an index on seid and an index on tiid.
Someone types in 1 or more tiid values and now I would like to get the seid with most results.
For example when someone types 1,2,3, I would like to get seid 2 and 4 as result. They both have 2 matches on the tiid values.
My query so far:
SELECT COUNT(*) as c, seid
FROM items
WHERE tiid IN (1,2,3)
GROUP BY seid
HAVING c = (SELECT COUNT(*) as c, seid
FROM items
WHERE tiid IN (1,2,3)
GROUP BY seid
ORDER BY c DESC
LIMIT 1)
But this query is extremly slow, because of the large table.
Does anyone know how to construct a better query for this purpose?
i have a problem with my PHP-MSSQL query.
i have a join table that need to give a result something be like this:
Department Group A Group B Total A+B
WORKHOUR A OTHOUR A WORKHOUR B OTHOUR B WORKHOUR OTHOUR
HR 10 15 25 0 35 15
IT 5 5 5 5
Admin 12 12 12 12
the query will count how many employee as per given date (admin will enter data and once submitted, the query will give the above result).
The problem is, the final output is a mess when there's no row to be displayed. the column is shifted to the right.
i.e:
only Group A in IT
only Group B in Admin
Department Group A Group B Total A+B
WORKHOUR A OTHOUR A WORKHOUR B OTHOUR B WORKHOUR OTHOUR
HR 10 15 25 0 35 15
IT 5 5 5 5
Admin 12 12 12 12
my question is, how to prevent this to happen?
i've tried everything with While.... if else.. but the result is still the same.
how to display output "0" if no rows to return?
echo "0";
this is my QUERY:
select DD.DPT_ID,DPT.DEPARTMENT_NAME,TU.EMP_GROUP, sum(DD.WORK_HOUR) AS WORK_HOUR,
sum(DD.OT_HOUR) AS OT_HOUR
FROM DEPARTMENT_DETAIL DD
left join DEPARTMENT DPT
ON (DD.DEPT_ID=DPT.DEPT_ID)
LEFT JOIN TBL_USERS TU
ON (TU.EMP_ID=DD.EMP_ID)
WHERE DD_DATE>='2012-01-01'
AND DD_DATE<='2012-01-31'
AND TU.EMP_GROUP!=2
GROUP BY DD.DEPT_ID, DPT.DEPARTMENT_NAME,TU.EMP_GROUP
ORDER BY DPT.DEPARTMENT_NAME
this is one of the logic that i've used, but doesn't return the result that i want::
while($row = mssql_fetch_array($displayResult))
{
if ((!$row["WORK_HOUR"])&&(!$row["OT_HOUR"]))
{
echo "<td >";
echo "empty";
echo " </td>";
echo "<td >";
echo "empty";
echo " </td>";
}
else
{
echo "<td>";
echo $row["WORK_HOUR"];
echo " </td>";
echo "<td>";
echo $row["OT_HOUR"];
echo " </td>";
}
}
please help. i've been doing this for 2 days. @__@
I'm working on a small project that involves grabbing a list of contacts which are stored for each group. Essentially, the database is set up so that each group has a primary and secondary contact stored as, unsurprisingly, Group.Primary and Group.Secondary. The objective is to pull every Primary and Secondary contact for each Group and display them in a sortable table.
I have the sortable table all worked out, but I have come across a small problem. Each primary and secondary field can have more than one contact separated by a comma. For instance, if Primary contained 123,256 , it would need to pull both Contacts with IDs 123 and 256. I had intended to use a query formatted like this:
SELECT *
FROM Group G,
Contacts C
WHERE G.Primary LIKE %C.ID%
OR G.Secondary LIKE %C.ID%
so that I could just skip the comma part, but I can't seem to find a working query for this.
My question to you is, am I just overlooking something here? Is there a simple query that would let me do this? Or am I better off getting the groups and contacts separately, and combine the two later. I think the former is a little easier to understand when read, which is a plus as this is a shared project, but if that is not possible I will do the latter.
This code is simplified, but it gets the point across.
What is the approach for storing the latitudes and longitudes for multiple addresses as a one time set up. I need to find the nearby stores using Google Maps and I have to get the latitudes and longitudes of all the available stores. As the data is huge and may increase or change in future, can anyone suggest an approach taking performance and maintenance into consideration.
Thank you.
I have table like below
id, employee_no, survey_no, name
1 test 1 test_name
2 test2 1 test_name2
3 test3 1 test_name3
4 test4 2 test_name4
how to query with Restriction.in by combining below AND into one IN statement?
IN[ (if(survey_no==1) && employee_no== 'test') ,
(if(survey_no==1) && employee_no== 'test2') ,
...
]
I am currently playing around with the idea of having history tables for some of my tables in my database. Basically I have the main table and a copy of that table with a modified date and an action column to store what action was preformed eg Update,Delete and Insert.
So far I can think of three different places that you can do the history table work.
Triggers on the main table for update, insert and delete. (Database)
Stored procedures. (Database)
Application layer. (Application)
My main question is, what are the pros, cons and gotchas of doing the work in each of these layers.
One advantage I can think of by using the triggers way is that integrity is always maintained no matter what program is implmentated on top of the database.