FireDAC Query connect to DBGrid - c++builder

I have FDQuery and DataSource and DBGrid. Now I write this code in Button
FDQuery2->Active = false;
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = " + MaskEdit1->Text +
" ORDER BY C.check_id ");
FDQuery2->Active = true;
and i connect FDQuery to DataSource and tDataSource to DBGrid, but when I click the Button it doesn't show rows. and i am sure that SQL code is work, because when i write inside the SQL String the rows have been shown.
any ideas.

You're missing the ' around your value when concatenating the text. Change your WHERE clause:
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = '" + MaskEdit1->Text + "'" +
" ORDER BY C.check_id ");
You really should learn to use parameterized queries instead, though. It allows the database driver to handle things like properly quoting text or formatting dates for you, and it also (importantly) prevents SQL injection.
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = :today" +
" ORDER BY C.check_id ");
FDQuery2->ParamByName("today")->AsString = MaskEdit1.Text;
FDQuery2->Active = true;

Related

Button click on Access form adds data to a table for specific column

I have a MS Access Form with a CWTButton
I am trying to fill the Table "Raw Data" column "CWT" with a "Yes" when it is clicked.
I'm really limited on my knowledge of programming so any help would be appreciated.
Private Sub CWTButton_Click()
INSERT INTO Raw Data (CWT)
VALUES ("Yes");
End Sub
I also tried
Private Sub CWTButton_Click()
Dim db As Database
Dim rs As DAO.Recordset
Set re = db.Raw Data
rs.AddNew
re("CWT").Value = "Yes"
rs.Update
End Sub
Fixed code thanks to #Gustav
Private Sub CWTButton_Click()
Dim Sql As String
Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES ('" & Me!Date.Value & "', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', '" & Me!Length.Value & "', '" & Me!Fish_ID.Value & "','" & Me!Comment.Value & "','Yes');"
CurrentDb.Execute Sql
End Sub
Try this:
Private Sub CWTButton_Click()
Dim Sql As String
Sql = "INSERT INTO [Raw Data] (CWT, Fish, Location) VALUES ('Yes', '" & Me!Fish.Value & "'," & Me!Location.Value & ");"
CurrentDb.Execute Sql
End Sub
' or:
Private Sub CWTButton_Click()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("[Raw Data]")
rs.AddNew
rs.Fields("CWT").Value = "Yes"
rs.Update
rs.Close
End Sub
For fields of DateTime ([Date]) or numbers (Length, ID), use no quotes:
Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES (#" & Format(Me!Date.Value, "yyyy\/mm\/dd" & "#', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', " & Me!Length.Value & ", " & Me!Fish_ID.Value & ",'" & Me!Comment.Value & "','Yes');"

WIQL query to get all item under a workitem

I am looking for a query where i can return all work items and their relation from a area path.
for example : project 1
i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,
in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.
string query1 = " SELECT * FROM WorkItemLinks " +
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
which throwing an error like below
An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code
Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».
when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine
string query = " SELECT * FROM WorkItems"+
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
//" AND ([System.State] = 'Active' OR [System.State] = 'Assessed' ) "+
//" AND ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.
You can try below query:
Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
namespace _0925_WIQL
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
new Uri("http://server:8080/tfs/CollectionLC"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
string query1= " SELECT * FROM WorkItemLinks " +
" WHERE ( Source.[System.IterationPath] Under 'TeamProject\\Iteration 1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
Query query = new Query(workItemStore, query1);
WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();
foreach (WorkItemLinkInfo witinfo in witLinkInfos)
{
.......
}
Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)

Write SQL query to Entity Framework

select *
from [InterViewerComment]
where commentID in (select max(commentID) as commentID
from [InterViewerComment]
where jobID = 45
group by qenID)
This query is correct in SQL, but I want to rewrite it in Entity Framework.
Basically, I want the latest comment for each qenID based on job ID.
Other way to do the same
var query = " select qendidateList.qenName,InterViewerComment.*, candidate_status.status, 0 as ExamMarks, 0 as Skills from [InterViewerComment] " +
" left outer join qendidateList on InterViewerComment.qenID = qendidateList.qenID " +
" left outer join candidate_status on InterViewerComment.candidate_status = candidate_status.Candidate_status " +
" where commentID in( select max(commentID) as commentID from[InterViewerComment] where jobID = 45 group by qenID)";
var CandidateComm_ = db.Database.SqlQuery<interViewerComment>(query).ToList();

SQLITE: INTERSECT / UNION Select Result & Normal Array

I use the solution below at the moment, the result is what I expected now.
myIDArray = #[#1, #2, #3];
...
executeQuery:[NSString stringWithFormat:#""
"SELECT name"
" FROM TABLE_A"
" WHERE a_id IN ("
" SELECT b_id"
" FROM TABLE_B"
" )"
" AND a_id IN %#", myIDArray];
But I wonder is there any way to INTERSECT two id lists inner IN (?)? Like
executeQuery:[NSString stringWithFormat:#""
"SELECT name"
" FROM TABLE_A"
" WHERE a_id IN ("
" SELECT b_id"
" FROM TABLE_B"
" INTERSECT"
" %#"// how to put my id array here appropriately?
" )", myIDArray];
Of course, this does not work, will throw syntax error.
I've also tried to use -componentsJoinedByString: to convert the array to string, w/ or w/o () for the string. No luck.
INTERSECT would require a query, so you would need a query that returns all these values:
... IN (SELECT b_id FROM TableB
INTERSECT
SELECT id FROM (SELECT 1 AS id UNION ALL
SELECT 2 UNION ALL
...
SELECT 42));
This is more verbose and less efficient than using two INs.

update table that contains single quote symbol with different online server in informix 4 gl

hi all,I am working on informix-4gl.my programs is about to adds and update user information from one tables to many tables.The tables are also must be update from different online server.The main tables is working on online06 named 'crsell' table and the other tables are on the online03 named 'cmpurc' table.This an example on how i update the tables.
## update CMPURC with latest purchaser info ##
LET ins_01 = NULL
LET ins_01 = "UPDATE bfs#", link_onln_no CLIPPED, ":cmpurc",
" SET cmp_purc_num = ", "'", p_cm_purc_num,
"'",",",
" cmp_purc_nme = ", "'",p_cmp_purc_nme,
"'",",",
" cmp_addr_1 = ", "'",p_cmp_addr_1, "'",",",
" cmp_addr_2 = ", "'",p_cmp_addr_2, "'",",",
" cmp_addr_3 = ", "'",p_cmp_addr_3, "'",
" WHERE cmp_proj_cde = ", "'", p_crsell.crse_proj_cde,
"'",
" AND cmp_phase_num = ", "'", p_crsell.crse_phase_num,
"'",
" AND cmp_lot_num = ", "'", p_crsell.crse_lot_num, "'"
In case, there were information from user that contains "'" symbol or single quote such as the purchaser name or user address.My problems is when I update the tables,the information that contains single quote symbols will not updated to the 'cmpurc' tables on online03 server. there will show an error message SQL statement error number -201.
I had try to convert symbol "'" to other symbol "^" and update the tables.Then, I update again the 'cmpurc' table with the information that contains "'" symbols.This step are also produce an error.This is way on how i convert the symbol.
LET rmks_lgth = LENGTH(p_crsell.crse_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_crsell.crse_purc_nme[a] = "'" THEN
LET p_crsell.crse_purc_nme[a] = "^"
END IF
END FOR
convert back to single quotes symbol
LET rmks_lgth = LENGTH(p_cmp_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_cmp_purc_nme[a] = "^" THEN
LET p_cmp_purc_nme[a] = "'"
END IF
END FOR
i had test by replacing the "'" symbol with the other values and its produce no error. The error will only occurs when the "'" symbol are being transfer from table 'crsell' to 'cmpurc'.I hope that someone can help me to solve my problems.I am sorry if there is lack of information that i had given to you because i cant post the image because lack of reputation and i am new user .I am very appreciate if you all can help me to solve the problems. thank you very much
Now, I am going to change single quotes to double quotes.I had try change code like this but its reads only single quotes.anyone can give an idea? thank you
LET rmks_lgth = LENGTH(p_crsell.crse_purc_nme)
FOR a = 1 TO rmks_lgth
IF p_crsell.crse_purc_nme[a] = "'" THEN
LET p_crsell.crse_purc_nme[a] = "''"
END IF
END FOR
I believe you need to duplicate the quote or double quote to get just one without syntax error...
This example I run into dbaccess without problem, I don't test into 4gl code...
create temp table tp01( desc char(20), desc2 char(20) ) ;
Temporary table created.
insert into tp01 values ( "tst""1", "tst'");
1 row(s) inserted.
insert into tp01 values ( 'tst''1', 'tst"');
1 row(s) inserted.
select * from tp01;
desc desc2
tst"1 tst'
tst'1 tst"
2 row(s) retrieved.

Resources