ContentUris.withAppendedId method in android content provider can i leave the "id" part of perameter blank? - sql-update

for the following method
Uri uri = ContentUris.withAppendedId((MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
i have read many examples but none of the examples tell me what to do with "id" part of the perameter, i don't want to assign which row because that will change depending of what row the specific image is stored in. so i can't hard code "id". how to deal with this? and can i leave the id as null?
edit
i just found this a few minutes ago from a website, http://www.grokkingandroid.com/android-tutorial-using-content-providers/
values.clear();
values.put(Words.WORD, "Zaphod");
Uri uri = ContentUris.withAppendedId(Words.CONTENT_URI, id);
long noUpdated = resolver.update(uri, values, null, null)
here is the quote from the author, "Since I changed only one record, a URI with an appended ID is sufficient. But if you want to update multiple values, you should use the normal URI and a selection clause."
so he says to use a "normal URI and selection clause" so how do i do that?
this is my selection statement:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
where "filename" is a string variable that varies depending on the image selected, for example, in this case /mnt/sdcard/pic09.png

I'm not sure if I understood your question, but regarding the part when you ask how do you do the normal URI and selection clause, the "trick" is that using content providers you dont put the whole selection in one argument as:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
but instead, you introduce the selection type, selection arguments through different input variables. So for example, the
update where MediaStore.Images.Media.DATA equals filename
becomes:
update (uri, contentValues, String selection, String[] selectionArgs)
where uri points to the table (not the row)
content values point to a ContentValues object with your new values
selection must contain the fields to be compared + comparrisson type + question mark, as
MediaStore.Images.Media.DATA + " = ?";
And selection arguments is an array with all the strings replacing question marks on your selection string, so in your case just
{filename}

Related

aspose mail merge layout not follow word template

I use aspose word, create a datatable, add column, and then mail merge with the word template. But I find in the output, the column width is very different from the word template (e.g. the last column "last date of duty"), why?
The code is as follows:
DataTable tableOrders = new DataTable("Orders");
tableOrders.getColumns().add("rank");
tableOrders.getColumns().add("staffNo");
tableOrders.getColumns().add("name");
tableOrders.getColumns().add("idNo");
tableOrders.getColumns().add("nature");
tableOrders.getColumns().add("effDate");
tableOrders.getColumns().add("b4effDate");
while(i.hasNext()) {
Object[] rs = (Object[]) i.next();
String rank = rs[0]==null?"":rs[0].toString();
String staffNo = rs[1]==null?"":rs[1].toString();
String name = rs[2]==null?"":rs[2].toString();
String id_no = rs[3]==null?"":rs[3].toString();
String nature = rs[4]==null?"":rs[4].toString();
String effDate = rs[5]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[5]);
String lastDutyDate = rs[6]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[6]);
// Create the orders table.
tableOrders.getRows().add(rank, staffNo, name, id_no, nature, effDate, lastDutyDate);
}
doc.getMailMerge().executeWithRegions(tableOrders);
doc.getMailMerge().execute(new String[] {"currentDate"}, new String[] {sdf2.format(new Date())});
As I can see you are saving your output document as PDF. The problem might occur because your table layout is built improperly. But it is difficult to say without your a real document. You can post your question and attach your document in Aspose.Words support forum.
Also, you can try configuring your template to use Fixed Column Width.
Most likely, in your template, auto fit behavior is set to AutoFit to Contents and after executing mail merge column widths are adjusted according to the data.

Extracting String Portions in SQL using Regular expressions

Hi All,
I have a query related to Regular expressions in SQL.
I have a case where a portion of string has to be extracted from a column. The portion of that column will be prefixed with my column A. Please see the screenshot for the sample data. I have also added the output expected in a separate column (highlighted in green).
Scenarios:
Now if a column value has more than 1 unique number then that has to be shown up with Null
Eg: To verify CAN06010025, CAN06010026 & CAN06010030 after the approval.
In the above string I have more than 1 number(bold portion)
and this case should be ignored (meaning it has to give me Null Value).
If there is only one number and if it is repetitive then I have to consider that case and extract the portion of String..
Eg: Project USA12: Id USA12S001: Contact required -USA12S001- form to be updated
In this example, the portion I wanted to extract is repetitive and I am looking to extract the highlighted portion alone.
The same applies to the other cases as well.
I tried with the below sql. The challenge is my Col A can also be present in Col B (Line 2 in screenshot) and this code is considering my Col A portion when I count with REGEXP_COUNT function and is giving me the value as Null. My expectation is to extract that USA12S001 portion from the column.
Could you please help in achieving this where the above two conditions satisfies.
SQL:
SELECT
ColA,
ColB,
case when REGEXP_COUNT(ColB,ColA) >2 THEN NULL
ELSE REPLACE(REPLACE(concat(regexp_substr(ColB,ColA||'([[:alnum:]]+\.?)'),
nvl(regexp_substr(ColB,ColA||'(\-[[:digit:]]+)'),
regexp_substr(ColB,ColA||'([[:space:]]\-[[:space:]][[:digit:]]+)'))),
' ',''),'.','')
END AS Result
FROM
table
Test Data:
Col A
CAN06
USA12
USA27
HUN04
CAN05
USA24
CAN06
Col B
to verify CAN06010025, CAN06010026 & CAN06010030 after the approval
Project USA12: Id USA12S001: Contact required -USA12S001- form to be updated
Project USA27: Id: USA27S001: Prod
To review id HUN04S002-HUN04S004 after the due date.
ID: CAN05S005 with the details as CAN05S005 are completed.
Project USA24: Id: USA24S009: Data Issue
"Project: Subject CAN06S009: V2 & V3- Id CAN06S010: V1"
If the REGEXP_COUNT is the only issue, then the answer is simple: change
case when REGEXP_COUNT(ColB,ColA) >2
to:
case when REGEXP_COUNT(ColB,ColA || '[[:alnum:]]') >2

calculated fields in TestTrack, how to add the field to itself?

i need to to add a text calculated field in TestTrack, so the field always add itself and then anoter field.
so the field will always contain the previous entry and the new one.
how can i do it ?, without the testtrack claiming its a recursive formula
the only way to dit is to do a count of the event (adding data to the field)
and than run a for each of the ocurrnces with a concatenate of the data with the string itself (old value).
here is the example that works for me :
var TicketCount=Item.Events.count("update ticket");
var ticketsStr ='';
for(ticketIndex = 0;ticketIndex < TicketCount;ticketIndex++)
{
ticketsStr = ticketsStr + Item.Events.at(ticketIndex,"update ticket").fieldValue("Customer Name");
if(ticketIndex < TicketCount-1)
ticketsStr = ticketsStr + ",";
}
result = ticketsStr;
You are correct that a TestTrack calculated field cannot reference itself in the formula. Even if it could reference itself, consider the following formula for "update ticket":
Item.fieldValue("update ticket")+Item.fieldValue("Type")
In this scenario, the Type value would always be appended but there would be no check to see if the Type value is already in the list. Every time an item is edited the "update ticket" field value would be recalculated and the Type value would be appended again whether it has changed or not.
The solution proposed by Tal solves this problem by looping through the other fields and re-building the value. Additionally if a Customer Name value is modified or deleted, the field value will be correctly calculated.

VBA Validation List Error

I am pretty new to programming in vba. I need some coding help which I am not able to find the solution after I tried Googling for the solution.
Currently I have a self-defined type called category mapping. The type will be used to contain the items which I want to put as the option for the vadliation list. It looked as below:
Public Type categoryMapping
messageKey As Long
description As String
End Type
An example of the categoryMapping is to store gender codes, 6000 stands for Male, 6001 stands for Female.
Display of the Validation List
As I have all stored them in an array, displaying them is not easy. What I have done is as below:
'Validation drop down list for the whole row
If Has_Elements(mapping) Then
Dim code As String
Dim options() As categoryMapping
code = ""
options = mapping
Dim j As Integer
For j = LBound(options) To UBound(options)
code = code & options(j).messageKey & ": " & options(j).description & ","
Next j
With Range(Rows(7).Address).Validation 'TODO: Need to refactor
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=code
.InCellDropdown = True
.InputMessage = "Please choose from of the following"
.ShowInput = True
End With
End If
Is there a easier to display them since I have already put all the item to be displayed into a array? Is it possible that I can call the array directly?
Use Cells
From the code above, it can be seen that I have use the address of the whole row to contain validation list, because actually what I want is the whole row, except the header cells to contain the validation list.
With Cells(7,1).Validation 'TODO: Need to refactor
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=code
.InCellDropdown = True
.InputMessage = "Please choose from of the following"
.ShowInput = True
End With
I tried using the code above to do, but it fails. Is there any way to go about doing it?
Combine multiple validation delete
Due to the problem mentioned above, I need to put in the code to delete the validation list for some column, as shown below:
'Delete the unneccessary validation
'TODO: refactor the code so that write in 1 line
Range(Columns(1).Address).Validation.Delete
Range(Columns(2).Address).Validation.Delete
Range(Columns(3).Address).Validation.Delete
Range(Columns(4).Address).Validation.Delete
Is there some ways that I can combine all the delete validation into a single statement?
Display part of the option
As you can see from above, when my users select a option from the validation list, the whole string appear.
For example, if I have "6000: Male" & "6001: Female" as the option, and I choose Male, I wished for "6000" to appear instead of "6000: Male". Is there a way to do it?
Validation data not exist after reopen
After I generate the validation list, I close the program and reopen it, there is a error that say "Excel found unreadable content in 'File name.xls'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
When I click Yes, my excel open but all my validation list is gone! And I got the below as a error message.
-
error064240_01.xml
Errors were detected in file 'file_name'
-
Removed Feature: Data validation from /xl/worksheets/sheet2.xml.part
I was guessing that the error occur because the option in the validation list is not stored in the worksheet, but it is stored in the program memory, hence when I closed the program, the memory is loss.
If my guess is correct, is there any way to go around solving this problem? I was thinking of creating another worksheet that contain all the data in the validation list and let my cell validation list refer to them, but is there better ways to store them in the same worksheet?
The unreadable content is because you are storing the validation list in an array in memory. As soon as you close the worksheet, that array goes out of scope and ceases to exist. Rather than storing it in an array, write the list to a worksheet somewhere, I normally create a new sheet called lists.
The actual validation for your cell won't use VBA. Just create a dynamic named range (using offset() and counta() to populate your validation list from the relevant column in the lists sheet. Then use your VBA code to write the array above to that column. (http://chandoo.org/wp/2010/09/13/dynamic-data-validation-excel/)
As far as displaying different text in the validation and the dropdown, that sounds like more trouble than it is worth. Is it possible to just resize your cell so it only shows the first 4 digits?

how to add fieldname as a variable in OCCI

In the below C++ code, i am updating a field of emp table based on the search value. But this code is not working properly. I am getting output as aborted.
void UpdateData(string field_name,string updated_value,string search_value)
{
stmt->createStatement("UPDATE emp SET :1=:2 where search=:3");
stmt->setString(1,field_name);
stmt->setString(2,updated_value);
stmt->setString(3,search_value);
stmt->executeUpdate();
}
In my program user will select which field they have to update and the selected field name is passed into function as field_name parameter. updated_value is the new value entered by the user and search_value is the search key to find the appropriate record.
If i do like
stmt->createStatement("UPDATE emp SET field_name=:2 where search=:3");
its working..
But the problem is, the field name will change according to user selection. How i can overcome this problem. Is there any other way ?
You can't set the name of the field with the statement->setString() method; only the values of the variables can be bound like that.
I know of only two solutions to achieve this (both aren't particularly nice):
Dynamically create the statement string
string statement ="UPDATE emp SET " + fieldname + "=:1 where search=:2";
Prepare individual statements, each affecting one field and choose at runtime
const string STATEMENT_FIELD_CITY = "UPDATE emp SET CITY=:1 where search=:2";
const string STATEMENT_FIELD_LAND = "UPDATE emp SET LAND=:1 where search=:2";