From 00a653114b05092b76b244ceaa078b414b07c184 Mon Sep 17 00:00:00 2001 From: "brettw%gmail.com" Date: Tue, 7 Feb 2006 23:00:06 +0000 Subject: [PATCH] Bug 325812 r=annie.sullivan Add annotation Int64, remove variant functions. git-svn-id: svn://10.0.0.236/trunk@189366 18797224-902f-48f8-a5cc-f745e15eee43 --- .../places/public/nsIAnnotationService.idl | 66 ++++++++------ .../places/src/nsAnnotationService.cpp | 88 ++++++++++--------- 2 files changed, 85 insertions(+), 69 deletions(-) diff --git a/mozilla/browser/components/places/public/nsIAnnotationService.idl b/mozilla/browser/components/places/public/nsIAnnotationService.idl index de252ca4b88..273fcb92c6f 100644 --- a/mozilla/browser/components/places/public/nsIAnnotationService.idl +++ b/mozilla/browser/components/places/public/nsIAnnotationService.idl @@ -108,36 +108,37 @@ interface nsIAnnotationService : nsISupports * service, but are special cased in the protocol handler so they look like * annotations. Do not set favicons using this service. */ - void setAnnotation(in nsIURI aURI, in AUTF8String aName, in nsIVariant aValue, - in PRInt32 aFlags, in PRInt32 aExpiration); - - /** - * Sets an annotation just like setAnnotation, but takes a string as - * input, which will be more convenient for C++. - */ void setAnnotationString(in nsIURI aURI, in AUTF8String aName, in AString aValue, in PRInt32 aFlags, in PRInt32 aExpiration); /** - * Sets an annotation just like setAnnotation, but takes an Int32 as input - * for convenience. + * Sets an annotation just like setAnnotationString, but takes an Int32 as + * input. */ void setAnnotationInt32(in nsIURI aURI, in AUTF8String aName, in PRInt32 aValue, in PRInt32 aFlags, in PRInt32 aExpiration); /** - * Sets an annotation just like setAnnotation, but takes an Int64 as input - * for convenience. + * Sets an annotation just like setAnnotationString, but takes an Int64 as + * input. */ void setAnnotationInt64(in nsIURI aURI, in AUTF8String aName, in PRInt64 aValue, in PRInt32 aFlags, in PRInt32 aExpiration); + /** + * Sets an annotation just like setAnnotationString, but takes a double as + * input. + */ + void setAnnotationDouble(in nsIURI aURI, in AUTF8String aName, + in double aValue, in PRInt32 aFlags, + in PRInt32 aExpiration); + /* - * Sets an annotation just like setAnnotation, but takes binary data as - * input. You MUST supply a valid MIME type. + * Sets an annotation just like setAnnotationString, but takes binary data + * as input. You MUST supply a valid MIME type. */ void setAnnotationBinary(in nsIURI aURI, in AUTF8String aName, [const,array,size_is(aDataLen)] in octet aData, @@ -145,34 +146,41 @@ interface nsIAnnotationService : nsISupports in PRInt32 aFlags, in PRInt32 aExpiration); /** - * Retrieves the value of an existing annotation. Throws if the annotation - * does not exist. - */ - nsIVariant getAnnotation(in nsIURI aURI, in AUTF8String aName); - - /** - * Same as getAnnotation but a convenience function for C++ for strings. + * Retrieves the string value of a given annotation. Throws an error if the + * annotation does not exist. If the annotation was set as a different + * type than you are retrieving it as, the value will be converted as best + * as we can. You aren't always guaranteed a good conversion, however, + * and errors will not be thrown in this case. (For example, doubles will + * lose precision when stringified.) */ AString getAnnotationString(in nsIURI aURI, in AUTF8String aName); /** - * Same as getAnnotation but a convenience function for C++ for ints. If - * the value doesn't look like an int, returns 0. (this is current sqlite - * behavior when asking for an int when there is not one, it will likely - * change in the future if we start caching stuff). + * Same as getAnnotationString but for ints. If the value doesn't look like + * an int, returns 0. (this is current sqlite behavior when asking for an + * int when there is not one, it will possibly change in the future if we + * start caching stuff). */ PRInt32 getAnnotationInt32(in nsIURI aURI, in AUTF8String aName); /** - * Same as getAnnotation but a convenience function for C++ for int64s. If - * the value doesn't look like an int, returns 0. (this is current sqlite - * behavior when asking for an int when there is not one, it will likely - * change in the future if we start caching stuff). + * Same as getAnnotationString for Int64s. If the value doesn't look like + * an int, returns 0. (this is current sqlite behavior when asking for an + * int when there is not one, it will possibly change in the future if we + * start caching stuff). */ PRInt64 getAnnotationInt64(in nsIURI aURI, in AUTF8String aName); /** - * Same as getAnnotation but for binary data. This also returns the + * Same as getAnnotationString but returns a double-precision float. If the + * value doesn't look like an float, returns 0. (this is current sqlite + * behavior when asking for an number when there is not one, it will + * possibly change in the future if we start caching stuff). + */ + double getAnnotationDouble(in nsIURI aURI, in AUTF8String aName); + + /** + * Same as getAnnotationString but for binary data. This also returns the * MIME type. */ void getAnnotationBinary(in nsIURI aURI, in AUTF8String aName, diff --git a/mozilla/browser/components/places/src/nsAnnotationService.cpp b/mozilla/browser/components/places/src/nsAnnotationService.cpp index aa4c00c702b..97e9feabe6b 100644 --- a/mozilla/browser/components/places/src/nsAnnotationService.cpp +++ b/mozilla/browser/components/places/src/nsAnnotationService.cpp @@ -116,23 +116,6 @@ nsAnnotationService::Init() } -// nsAnnotationService::SetAnnotation - -NS_IMETHODIMP -nsAnnotationService::SetAnnotation(nsIURI* aURI, - const nsACString& aName, - nsIVariant *aValue, - PRInt32 aFlags, PRInt32 aExpiration) -{ - if (! aValue) - return NS_ERROR_INVALID_ARG; - nsAutoString stringValue; - nsresult rv = aValue->GetAsAString(stringValue); - NS_ENSURE_SUCCESS(rv, rv); - return SetAnnotationString(aURI, aName, stringValue, aFlags, aExpiration); -} - - // nsAnnotationService::SetAnnotationString NS_IMETHODIMP @@ -229,6 +212,38 @@ nsAnnotationService::SetAnnotationInt64(nsIURI* aURI, } +// nsAnnotationService::SetAnnotationDouble + +NS_IMETHODIMP +nsAnnotationService::SetAnnotationDouble(nsIURI* aURI, + const nsACString& aName, + double aValue, + PRInt32 aFlags, PRInt32 aExpiration) +{ + mozStorageTransaction transaction(mDBConn, PR_FALSE); + mozIStorageStatement* statement; // class var, not owned by this function + nsresult rv = StartSetAnnotation(aURI, aName, aFlags, aExpiration, &statement); + NS_ENSURE_SUCCESS(rv, rv); + mozStorageStatementScoper statementResetter(statement); + + rv = statement->BindDoubleParameter(kAnnoIndex_Content, aValue); + NS_ENSURE_SUCCESS(rv, rv); + rv = statement->BindNullParameter(kAnnoIndex_MimeType); + NS_ENSURE_SUCCESS(rv, rv); + + rv = statement->Execute(); + NS_ENSURE_SUCCESS(rv, rv); + transaction.Commit(); + + // should reset the statement; observers may call our service back to get + // annotation values! + statement->Reset(); + statementResetter.Abandon(); + CallSetObservers(aURI, aName); + return NS_OK; +} + + // nsAnnotationService::SetAnnotationBinary NS_IMETHODIMP @@ -266,29 +281,6 @@ nsAnnotationService::SetAnnotationBinary(nsIURI* aURI, } -// nsAnnotationService::GetAnnotation - -NS_IMETHODIMP -nsAnnotationService::GetAnnotation(nsIURI* aURI, - const nsACString& aName, - nsIVariant** _retval) -{ - nsAutoString stringValue; - nsresult rv = GetAnnotationString(aURI, aName, stringValue); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr var = do_CreateInstance("@mozilla.org/variant;1", - &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = var->SetAsAString(stringValue); - NS_ENSURE_SUCCESS(rv, rv); - - *_retval = var; - NS_ADDREF(*_retval); - return NS_OK; -} - - // nsAnnotationService::GetAnnotationString NS_IMETHODIMP @@ -337,6 +329,22 @@ nsAnnotationService::GetAnnotationInt64(nsIURI* aURI, } +// nsAnnotationService::GetAnnotationDouble + +NS_IMETHODIMP +nsAnnotationService::GetAnnotationDouble(nsIURI* aURI, + const nsACString& aName, + double *_retval) +{ + nsresult rv = StartGetAnnotationFromURI(aURI, aName); + if (NS_FAILED(rv)) + return rv; + *_retval = mDBGetAnnotationFromURI->AsDouble(kAnnoIndex_Content); + mDBGetAnnotationFromURI->Reset(); + return NS_OK; +} + + // nsAnnotationService::GetAnnotationBinary NS_IMETHODIMP