So I have my rails application and I have blog posts in my application.
For starters I am on rails 2.3.5 and Ruby 1.8.7
For the show page, I am required to give a prev/next link to the prev/next blog post.
The catch is that I need to find the next blog where the language column in the database is equal to 'eng'. I had started writing this out in my model and it works but of course this will just find the prev/next record in the database no matter what the language is specified in the column and it will break when the record is not found.
def next(lang='eng')
BlogEntry.find(self.id - 1)
end
def prev(lang='eng')
BlogEntry.find(self.id + 1)
end
Hello All,
I am new to web application development, so sorry in advance if this question is too basic.
The following are the details of the question:
A] Platform being used --
google app engine with python, django.
B] Tutorial link being used -- http://code.google.com/appengine/articles/djangoforms.html
C] Question: In the application i am building, there is a drop down box which allows the user to select their country. Since the list of countries is above 200, i want to construct a database of the countries before the application loads.
Once this application is deployed, i dont want the database to get re-loaded again, since the entries are constant for all the users. How does one achieve this ?
thanks,
Lance.
Hi there,
I have a Java Web application using GlassFish 3, JSF2.0 (facelets) and JPA (EclipseLink). The problem I'm facing, is that if I'm saving entities to the database with the update() method, String data loses integrity; '?' is shown instead of some characters.
The server, pages and database is/are configured to use UTF-8.
After I post form data, the next page shows the data correctly. Furthermore it "seems" in debug that the String property of the current entity stores the correct value too. Dunno if NetBeans debug can be trusted; might be that it decodes correctly, however it's incorrect.
Any help would be appreciated, thanks in advance!
Daniel
Hi,
I need to Pass some data to text file. Then that text file should be save in Data Base(SQL 2005). Then i need to retrieve data from the database by reading the columns to my application. I use VS2005 and need C# solution.
Ex: (1) After click "Load" button data should pass to textile.
(2) Then Click "Save" button data need to pass to database.
(3) After click "Retrive" button data should load to datagride view.
Please Help.....
Hey All,
I am about to begin a project for a new client, and am worried about a few things concerning data usage on their internet plan. We're in an area where most of the major networks don't cover the area, and the ones that do, have very expensive plans, with very low data allowance per month.
I need to develop an app, but part of the problem lies with checking database values every 30 seconds. It's pretty important that this check is happening every 30 seconds, as the database is actually updated all day everyday, approx. every 5seconds (apparently).
Each row in the database consists of about a page full of text if you were to paste it into MS Word.
So, are there any logical ways of minimizing data usage in my case, and also how am I able to see exactly how much data is used just to establish a connection to the database? Are there any tools for this kind of info?
Thanks :)
I’m new (only two weeks old) in Jquery, so please bear with me.
I know that a very similar question was asked some time ago
but I do not know how to adapt the answer to my problem.
I have a very wide multicolumn layout something like this:
| aaaa | bbbb | cccc | … |
| aaaa | b | cc | … |
| aaa | cccc | ddd | … |
The code looks like:
<div id="container">
<p>aaaaaaaaaaa</p>
<p>bbbbb</p>
<p>ccccccccccc</p>
<p>dddddddddd</p>
...
<p>xxxxxx</p>
</div>
There is no vertical scrolling and the container width
is set in such a way that only two columns are shown.
The user scrolls left or right to see the relevant text.
What I want is to get the position currently on display,
store it (maybe in a cookie) and retrieve it the next
time the user opens the page.
I think that I need a way of finding out what paragraph
is currently the left-top most, but other suggestions
are very welcome.
Any ideas?
btw: this is an internal project, so Mozilla only :-)
Thanks
Lolo
I'm guessing this is impossible, but I'll throw it out there anyway. Is it possible to use CreateSourceQuery when programming with the EF4 CodeFirst API, in CTP4? I'd like to eagerly load properties attached to a collection of properties, like this:
var sourceQuery = this.CurrentInvoice.PropertyInvoices.CreateSourceQuery();
sourceQuery.Include("Property").ToList();
But of course CreateSourceQuery is defined on EntityCollection<T>, whereas CodeFirst uses plain old ICollection (obviously). Is there some way to convert?
I've gotten the below to work, but it's not quite what I'm looking for. Anyone know how to go from what's below to what's above (code below is from a class that inherits DbContext)?
ObjectSet<Person> OSPeople = base.ObjectContext.CreateObjectSet<Person>();
OSPeople.Include(Pinner => Pinner.Books).ToList();
Thanks!
EDIT: here's my version of the solution posted by zeeshanhirani - who's book by the way is amazing!
dynamic result;
if (invoice.PropertyInvoices is EntityCollection<PropertyInvoice>)
result = (invoices.PropertyInvoices as EntityCollection<PropertyInvoice>).CreateSourceQuery().Yadda.Yadda.Yadda
else
//must be a unit test!
result = invoices.PropertyInvoices;
return result.ToList();
EDIT2:
Ok, I just realized that you can't dispatch extension methods whilst using dynamic. So I guess we're not quite as dynamic as Ruby, but the example above is easily modifiable to comport with this restriction
EDIT3:
As mentioned in zeeshanhirani's blog post, this only works if (and only if) you have change-enabled proxies, which will get created if all of your properties are declared virtual. Here's another version of what the method might look like to use CreateSourceQuery with POCOs
public class Person {
public virtual int ID { get; set; }
public virtual string FName { get; set; }
public virtual string LName { get; set; }
public virtual double Weight { get; set; }
public virtual ICollection<Book> Books { get; set; }
}
public class Book {
public virtual int ID { get; set; }
public virtual string Title { get; set; }
public virtual int Pages { get; set; }
public virtual int OwnerID { get; set; }
public virtual ICollection<Genre> Genres { get; set; }
public virtual Person Owner { get; set; }
}
public class Genre {
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual Genre ParentGenre { get; set; }
public virtual ICollection<Book> Books { get; set; }
}
public class BookContext : DbContext {
public void PrimeBooksCollectionToIncludeGenres(Person P) {
if (P.Books is EntityCollection<Book>)
(P.Books as EntityCollection<Book>).CreateSourceQuery().Include(b => b.Genres).ToList();
}
I have to create an SQL Query to get all rows starting with a specific character, except if the parameter passed to the (PHP) function is 0, in that case it should get every row that does not start with A - Z (like #0-9.,$ etc).
What is the easiest and fastest way to get those rows?
DB: MySQL 5.1
Column: title
Hi All,
Here's what I want to do. I have 2 strings and I want to determine if one string is a permutation of another. I was thinking to simply remove the characters from string A from string B to determine if any characters are left. If no, then it passes.
However, I need to make sure that only 1 instance of each letter is removed (not all occurrences) unless there are multiple letters in the word.
An example:
String A: cant
String B: connect
Result: -o-nec-
Experimenting with NSString and NSScanner has yielded no results so far.
Hello everyone,
I have two SQL Server 2008 Enterprise databases (on two machines), and one of the databases is master database and another database is slave database.
I want to transfer update from a table in source database to a table in destination database (two tables are of the same schema, both of them are using a single column as unique primary key). The transfer rule is (in short, the rule is keeping the destination database the same as source database because of the update of the source database),
if there is a new row in source database but not in destination database, insert the row in destination database;
if a row not exists in source database but exists in destination database, delete the row in destination database;
if a row's content (i.e. columns other than primary key columns) changes in source database, update the new content into destination database.
thanks in advance,
George
i have been asked by a client to develop a javascript(mootools)/html/css/php based game as a widget which can be deployed anywhere.
I have not written a widget before, so would love to get some tips and experiences so that i know some of the pitfalls before i start!
Thanks :)
Dan
Hi there
I am new at this so please bear with me...
I have managed to get the following code to work...so when I click on the "select" link in each row of the gridview, the data is transfered to other label/textbox on the webpage.
So far so good, the thing is that everytime I click on select...it goes and checks on the database for the data and there is a delay of a few seconds...
I was hoping that the data, since it is already visible on the gridrows, is simply "picked up" and used on other labels/textboxes...without requerying the database.
Is this possible ?
Thanks in advance
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = GridView2.SelectedRow.Cells(8).Text
Label2.Text = GridView2.SelectedRow.Cells(9).Text
TextBox1.Text = GridView2.SelectedRow.Cells(7).Text
End Sub
I would like to create a predicate to search for a specific letter at the start of each word in a string of words e.g. all words starting with A in @"The man ate apples", would return ate and apples. Is it possible to create such a predicate? Thank you.
I would like to use the EmailField in a form. However, instead of only storing
[email protected]
I want to store
"ACME Support" <[email protected]>
The reason is, that when I send email, I would like a "friendly name" to appear.
Can this be done?
I am currently using the JQuery ajax function to call an exterior PHP file, in which I select and add data in a database. Once this is done, I run a success function in JavaScript. What's weird is that the database is updating successfully when ajax is called, however the success function is not running. Here is my code:
<!DOCTYPE html>
<head>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
</head>
<body>
<div onclick="addtask();" style="width:400px; height:200px; background:#000000;"></div>
<script>
function addtask() {
var tid = (Math.floor(Math.random() * 3)) + 1;
var tsk = (Math.floor(Math.random() * 10)) + 1;
if(tsk !== 1) {
$.ajax({
type: "POST",
url: "taskcheck.php",
dataType: "json",
data: {taskid:tid},
success: function(task) {alert(task.name);}
});
}
}
</script>
</body>
</html>
And the PHP file:
session_start();
$connect = mysql_connect('x', 'x', 'x') or die('Not Connecting');
mysql_select_db('x') or die ('No Database Selected');
$task = $_REQUEST['taskid'];
$uid = $_SESSION['user_id'];
$q = "SELECT task_id, taskname FROM tasks WHERE task_id=" .$task. " LIMIT 1";
$gettask = mysql_fetch_assoc(mysql_query($q));
$q = "INSERT INTO user_tasks (ut_id, user_id, task_id, taskstatus, taskactive) VALUES (null, " .$uid. ", '{$gettask['task_id']}', 0, 1)";
$puttask = mysql_fetch_assoc(mysql_query($q));
$json = array(
"name" => $gettask['taskname']
);
$output = json_encode($json);
echo $output;
Let me know if you have any questions or comments, thanks.
Hello
I have a short question to the notepad tutorial on the android website. I wrote a simple function in the tutorial code to delete the whole database. It looks like this:
DataHelper.java
public void deleteDatabase() {
this.mDb.delete(DATABASE_NAME, null, null);
}
Notepadv1.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, DELETE_ID, 0, "Delete whole Database");
return result;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case DELETE_ID:
mDbHelper.deleteDatabase();
return true;
}
return super.onOptionsItemSelected(item);
}
But when I run the app and try to delete the database I will get this error in LogCat:
sqlite returned: error code = 1, msg= no such table: data
Can you help how to fix this problem. It seems that the function deleteDatabase can not reach the database.
Thank you very much.
Felix
We are really in a mess. The following is what happened.
We have taken backup of WSS_Content database.
From Central Administration Page we remove the database.
Added a new database for the website.
Now we are getting the below error
HTTP/1.1 404
Connection: close
Date: Wed, 07 Apr 2010 10:04:54 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 12.0.0.4518
Even replacing the database not helping. Can someone help us??
Hello:
In short, currently I am using the following code to pull records from multiple tables in a Sqlite Db and insert them in a single combobox ($SearchBar):
set SrchVals1 [db eval {SELECT DISTINCT Stitle From Subcontract Order By Stitle ASC}]
set SrchVals2 [db eval {...
set SrchVals3 ...
set SrchValsALL [concat $SrchVals1 $SrchVals2 $SrchVals3]
$SearchBar configure -value $SrchValsAll
For the variable "SrchVals1", I am trying to figure out a way to concatenate the text "Sub: " to each individual record in SrchVals1. For example, if SrchVals1 shows the following records in the combobox:
First Title
Second Title
Third Title
I would like to concatenate so that the records in the combobox look like this:
Sub: First Title
Sub: Second Title
Sub: Third Title
I understand that I might have to use a foreach statement; however, I am having no luck writing one that adds "Sub: " in front of each record, as opposed to one. This seems like something that should be pretty easy, but I cannot seem to figure it out.
Does anyone know how I can achieve these results?
Thank you,
DFM
I have created a database model in Visio Professional (2003). I know that the Enterprise version has the ability to create a DB in Sql Server based on the data in Visio. I do not have the option to install Enterprise. Aside from going through the entire thing one table and relationship at a time and creating the whole database from scratch, by hand, can anyone recommend any tool/utility/method for converting the visio database model into a Sql Script that can be used to create a new DB in Sql Server?
I'm using SchemaUpdate to synchronize my hbms with existing database. Database has recently created based on hbms and is completely up-to-date. But SchemaUpdate generates all foreign key constraints again.
For example suppose you have Student and Teacher. Student has association to Teacher with name ArtTeacher. ArtTeacher is a foreign key from Student to Teacher. Suppose database is up-to-date and currently holde Student, Teacher and their foreign key relation. So HBM and Database are equivalent. Know SchemaUpdate must not do anything but when I see its generated scripts, it re-produce that foreign key again.
Why this happens? Is there any way to avoid it?
I don't know how to search about this so I'm kinda lost (the two topics I saw here were closed).
I have a news website and I want to warn the user when a new data is inserted on the database. I want to do that like here on StackOverflow where we are warned without reloading the page or like in facebook where you are warned about new messages/notifications without reloading.
Which is the best way to do that? Is it some kind of listener with a timeout that is constantly checking the database? It doesn't sounds efficient...
Thanks in advance.
I have created a web app version of my previous crawler app and the initial form has controls to allow the client to make selections and start a search 'job'.
These searches 'jobs' will be run my different threads created individually and added to a list to keep track of. Now the idea is to have another web form that will display this list of 'jobs' and their current status and will allow the jobs to be cancelled or removed only from the server side.
This second form contains a grid to display these jobs. Now I have no idea if I should create the threads in the initial form code or send all user input to my main class which runs the search and if so how do I pass the the thread list to the second form to have it displayed on the grid.
Any ideas really appreciated.
Dim count As Integer = 0
Dim numThread As Integer = 0
Dim jobStartTime As Date
Dim thread = New Thread(AddressOf ResetFormControlValues) 'StartBlogDiscovery)
jobStartTime = Date.Now
thread.Name = "Job" & jobStartTime 'clientName
Session("Job") = "Job" & jobStartTime 'clientName
thread.start()
thread.sleep(50000)
If numThread >= 10 Then
For Each thread In threadlist
thread.Join()
Next
Else
numThread = numThread + 1
SyncLock threadlist
threadlist.Enqueue(thread)
End SyncLock
End If
this is the code that is called when the user clicks the search button on the inital form.
this is what I just thought might work on the second web form if i used the session method.
Try
If Not Page.IsPostBack Then
If Not Session("Job") = Nothing Then
Grid1.DataSource = Session("Job")
Grid1.DataBind()
End If
End If
Finally